备注:待验证。

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、以下待验证、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

今天度娘发现这个内容,原来我一直做的都能直接有函数方法,汗死姐了。

jQuery.postJSON()

我不明白为何 jQuery 没有把这个方法加进去,虽然他们有 $.getJSON 方法。

$.postJSON(
"/put/path/here",
{val1: "Cheetos", val2: "Nachos"},
function(response){ //on success do something }
);

  

jQuery.stop()

这个方法是用来停止事件传递的。它接受两个参数,preventDefault 和 stopPropgation。

$.stop(event, preventDefault, stopPropagation);
$("#container").click(function(e)
{
$.stop(e, true, true);
});

  

jQuery.shuffleArray()

这个我用的不多,但是很好用,它可以随机的打乱一个数组。

$.shuffleArray([1,2,3,4,5,6,7]); //potential output: [1,3,5,7,2,4,6]

  

jQuery.reload()

这个函数就是“window.location.reload(true)”的缩写。

$.reload();

  

jQuery.uri()

这个函数可以解析 URL 的 URI 部分,可以通过 index 的方式访问,从1开始。

http://www.domain.com/this/domain/rocks

$.uri(1); //will output this
$.uri(3); //will output rocks

  

jQuery.URLParams()

这个函数我起码写过100遍。

http://www.domain.com/this/domain/rocks?param=fantastic&test=awesome#websanova

$.URLParams(); // {param: 'fantastic', test: 'awesome'}
$.URLParams('test'); // awesome

  

jQuery.URLHash()

这个函数类似 URLParams,但是它返回的是 URL 中的 “#” 部分,如果有的话。

http://www.domain.com/this/domain/rocks?param=fantastic&test=awesome#websanova

$.URLHash(); // websanova

  

jQuery.hexToRGB()

这个函数也很好用,它接受一个十六进制的数字,或者RGB字符串,相互转换,非法数据会返回 false。

$.hexToRGB("#FF3388"); // rgb(255,51,136)
$.hexToRGB("#F38"); // rgb(255,51,136)
$.hexToRGB("#ZZ3388"); // false
$.hexToRGB("F38A"); // false $.hexToRGB("rgb(22,67,234)"); // #1643EA
$.hexToRGB("rgb(22,67,274)"); // false
$.hexToRGB("rgb(22,67)"); // false

  

jQuery.base64Encode()

将 UTF-8 的字符串用 base64 编码。

$.base64Encode("encode this string"); // ZW5jb2RlIHRoaXMgc3RyaW5n

  

jQuery.base64Decode()

base64 解码,同样也是 UTF-8 编码。

$.base64Decode("ZW5jb2RlIHRoaXMgc3RyaW5n"); // encode this string

  

jQuery.utf8Encode()

将 String 转换成 UTF-8 编码的,主要用于上面提到的 base64Encode 函数。

$.utf8Encode("utf8 encode this");

  

jQuery.utf8Decode()

UTF-8 解码。

$.utf8Decode("utf8 encode this");

  

.removeClassRegEx()

这个方法真是太好用了,可以移除指定元素的指定 class。

<div class="test testing leavemealone hellotest Tester"></div>

$("#container").removeClassRegEx(/test/i);  //class="leavemealone"
$("#container").removeClassRegEx(/test/); //class="leavemealone Tester"
$("#container").removeClassRegEx(/^test/i); //class="leavemealone hellotest"
$("#container").removeClassRegEx(/test$/); //class="testing leavemealone Tester"

  

.hasClassRegEx()

和 removeClassRegEx 类似,这个方法检查指定元素是否有指定的 class。

<div class="test testing leavemealone hellotest Tester"></div>

$("#container").removeClassRegEx(/test/i);    // true
$("#container").removeClassRegEx(/test/); // true
$("#container").removeClassRegEx(/^test/i); // true
$("#container").removeClassRegEx(/test$/); // true
$("#container").removeClassRegEx(/^testy$/); // false

  

.maxChars()

这个函数对那些没有“maxlength”属性的input元素就很有用。它也可以指定一个元素来显示剩余字符。

$("input").maxChars(50);
$("input").maxChars(50, $("#maxChars_counter"));

  

Object.sizeof()

这个方法是 JavaScript 的一个扩展,可以让你获取对象的长度。

{cow: "moo", duck: "quack"}.sizeof(); // 2

  

String.capitalize()

这是 String 对象的一个扩展,可以把一个字符串变成大写的。

"test".capitalize(); // Test

  

String.pxToInt()

这个方法用了很多,特别是在我返回一个 CSS 属性的时候,我希望得到一个整数。

"210px".pxToInt(); //210
$("container").css('height').pxToInt(); // 400

  

jQuery 工具类库集锦的更多相关文章

  1. 5个最顶级jQuery图表类库插件-Charting plugin

    转载: http://www.cnblogs.com/chu888chu888/archive/2012/12/22/2828962.html 作者:Leonel Hilario翻译:Terry li ...

  2. 从零开始学习jQuery (九) jQuery工具函数

    一.摘要 本系列文章将带您进入jQuery的精彩世界, 其中有很多作者具体的使用经验和解决方案,  即使你会使用jQuery也能在阅读中发现些许秘籍. 我们经常要使用脚本处理各种业务逻辑, 最常见的就 ...

  3. 编写更少量的代码:使用apache commons工具类库

    Commons-configuration   Commons-FileUpload   Commons DbUtils   Commons BeanUtils  Commons CLI  Commo ...

  4. jquery常用代码集锦

    1. 如何修改jquery默认编码(例如默认GB2312改成 UTF-8 ) 1 2 3 4 5 $.ajaxSetup({     ajaxSettings : {         contentT ...

  5. 尝试造了个工具类库,名为 Diana

    项目地址: diana 文档地址: http://muyunyun.cn/diana/ 造轮子的意义 为啥已经有如此多的前端工具类库还要自己造轮子呢?个人认为有以下几个观点吧: 定制性强,能根据自己的 ...

  6. Python全栈-JavaScript】jQuery工具

    jQuery工具 一.jQuery.browser.version 显示当前 IE 浏览器版本号. if ( $.browser.msie ) alert( $.browser.version ); ...

  7. Flutter 常用工具类库common_utils

    地址:https://pub.flutter-io.cn/packages/common_utils#-readme-tab- Dart常用工具类库 common_utils 1.TimelineUt ...

  8. JSON工具类库: alibaba/fastjson 使用记录

    JSON工具类库: alibaba/fastjson 使用记录 一.了解JSON JSON标准规范中文文档: http://www.json.org/json-zh.html 最佳实践:http:// ...

  9. Java_图片处理_02_图片处理工具类库

    二.参考文档 1.Java图片处理工具类库

随机推荐

  1. CSS 实现:父元素包含子元素,子元素垂直居中布局

    ☊[实现要求]:父元素包含子元素,子元素垂直居中布局 <div class="demo5"> <div class="child">A& ...

  2. 【题解】【排列组合】【素数】【Leetcode】Unique Paths

    A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below). The ...

  3. Qt之QCheckBox

    简述 QCheckBox继承自QAbstractButton,它提供了一个带文本标签的复选框. QCheckBox(复选框)和QRadioButton(单选框)都是选项按钮.这是因为它们都可以在开(选 ...

  4. 正则表达式入门教程&&经典Javascript正则表达式(share)

    前言 例子: ^.+@.+\\..+$ 这样的代码曾经多次把我自己给吓退过.可能很多人也是被这样的代码给吓跑的吧.继续阅读本文将让你也可以自由应用这样的代码. 正文 教程:正则表达式30分钟入门教程 ...

  5. ZSDRM001-发货清单

    REPORT ZSDRM001 LINE-SIZE 225 LINE-COUNT 65 NO STANDARD PAGE HEADING.*------------------------------ ...

  6. ZOJ 1115 Digital Roots

    原题链接 题目大意:给一个数字,每一位相加求和,不断重复过程,直到剩一位数字. 解法:考虑到输入的数字可以很大,把输入按照字符串格式读入,再逐位处理. 参考代码: #include <iostr ...

  7. java List 排序 Collections.sort()

    用Collections.sort方法对list排序有两种方法  第一种是list中的对象实现Comparable接口,如下: /** * 根据order对User排序 */ public class ...

  8. com.google.guava 包解析 ——Google Guava官方教程(中文版)

    全网址           http://ifeve.com/google-guava/ 竹子博客:  http://www.cnblogs.com/peida/archive/2013/06/08/ ...

  9. 最大连续子序列和问题(Maximum Consecutive Subsequence Sum)

    该算法的定义是:给出一个int序列,元素有正有负,找出其中的最大连续子序列的和. 例如:-2,11,-4,13,-5-2,:最大和为20(11,-4, 13). 怎么考虑这个问题呢? 要充分利用,连续 ...

  10. (转载)Hadoop map reduce 过程获取环境变量

    来源:http://www.linuxidc.com/Linux/2012-07/66337.htm   作者: lmc_wy Hadoop任务执行过程中,在每一个map节点或者reduce节点能获取 ...