语法
公鸡酸是“准备事件”的简称
鸡酮酸的断行性和链性
嵌套过滤器由Nathan Long
缓存一个集合并通过roosteronacid在同一行上执行命令
包含选择器roosteronacid
定义元素创建时的属性
访问jQuery函数就像访问roosteronacid数组一样
noConflict函数- Oli释放$变量
通过nickf隔离noConflict模式下的$变量
无冲突模式由鸡酮酸
数据存储
数据函数-通过TenebrousX将数据绑定到元素
HTML5数据属性支持,在类固醇!由roosteronacid
Filip dupanovic设计的jQuery元数据插件
优化
用鸡酮酸优化复合选择剂的性能
lupefiasco的上下文参数
Nathan Long的保存和重用搜索
创建HTML元素并保持引用,检查元素是否存在,编写自己的选择器
杂项
Check the index of an element in a collection by redsquare
Live event handlers by TM
Replace anonymous functions with named functions by ken
Microsoft AJAX framework and jQuery bridge by Slace
jQuery tutorials by egyamado
Remove elements from a collection and preserve chainability by roosteronacid
Declare $this at the beginning of anonymous functions by Ben
FireBug lite, Hotbox plug-in, tell when an image has been loaded and Google CDN by Colour Blend
Judicious use of third-party jQuery scripts by harriyott
The each function by Jan Zich
Form Extensions plug-in by Chris S
Asynchronous each function by OneNerd
The jQuery template plug-in: implementing complex logic using render-functions by roosteronacid
而不是使用不同的别名为jQuery对象(当使用noConflict),我总是写我的jQuery代码包装在一个闭包。这可以在文档中完成。现成的函数:
var $ = someOtherFunction(); // from a different library
jQuery(function($) {
if ($ instanceOf jQuery) {
alert("$ is the jQuery object!");
}
});
或者你可以这样做:
(function($) {
$('...').etc() // whatever jQuery code you want
})(jQuery);
我觉得这个最方便携带。我一直在一个同时使用Prototype和jQuery的网站上工作,这些技术避免了所有的冲突。
为折叠以上的元素添加一个选择器
作为jQuery的选择器插件
$.extend($.expr[':'], {
"aboveFold": function(a, i, m) {
var container = m[3],
var fold;
if (typeof container === "undefined") {
fold = $(window).height() + $(window).scrollTop();
} else {
if ($(container).length == 0 || $(container).offset().top == null) return false;
fold = $(container).offset().top + $(container).height();
}
return fold >= $(a).offset().top;
}
});
用法:
$("p:aboveFold").css({color:"red"});
谢谢scottymac
在方法调用(如.append())中使用自动执行的匿名函数来遍历某些内容。例如:
$("<ul>").append((function ()
{
var data = ["0", "1", "2", "3", "4", "5", "6"],
output = $("<div>"),
x = -1,
y = data.length;
while (++x < y) output.append("<li>" + info[x] + "</li>");
return output.children();
}()));
我使用这种方法来迭代那些不适合跳出我的链接来构建的大而不舒服的东西。