语法

公鸡酸是“准备事件”的简称 鸡酮酸的断行性和链性 嵌套过滤器由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


当前回答

更新:

只要在站点上包含这个脚本,您就会得到一个Firebug控制台,可以在任何浏览器中进行调试。虽然功能不全,但还是很有用的!吃完之后记得把它拿掉。

<script type='text/javascript' src='http://getfirebug.com/releases/lite/1.2/firebug-lite-compressed.js'></script>

看看这个链接:

来自CSS技巧

更新: 我发现了一些新的东西;它是JQuery Hotbox。

JQuery轴承箱

谷歌在谷歌Code上托管了几个JavaScript库。从那里加载它可以节省带宽,而且加载速度很快,因为它已经被缓存了。

<script src="http://www.google.com/jsapi"></script>  
<script type="text/javascript">  

    // Load jQuery  
    google.load("jquery", "1.2.6");  

    google.setOnLoadCallback(function() {  
        // Your code goes here.  
    });  

</script>

Or

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script>

你也可以用它来判断图像何时完全加载。

$('#myImage').attr('src', 'image.jpg').load(function() {  
    alert('Image Loaded');  
});

firebug的"console.info",您可以使用它将消息和变量转储到屏幕上,而不必使用警告框。”控制台。Time”允许你轻松地设置一个计时器来包装一堆代码,并查看它需要多长时间。

console.time('create list');

for (i = 0; i < 1000; i++) {
    var myList = $('.myList');
    myList.append('This is list item ' + i);
}

console.timeEnd('create list');

其他回答

无耻的宣传……jQuery模板插件:使用渲染函数实现复杂的逻辑

The new jQuery template plug-in is awesome. That being said, the double-curly brace template-tags are not exactly my cup of tea. In a more complex template the tags obscure the templates markup, and implementing logic past simple if/else statements is a pain. After messing around with the plug-in for a few hours, my head began to hurt from trying to distinguish the markup in my template from the millions of double curly braces. So I popped an aspirin and began work on an alternative

似乎大多数有趣和重要的技巧都已经提到了,所以这一点只是一个小小的补充。

这个小技巧就是jQuery。每个(对象,回调)函数。每个人都可能使用jQuery.each(回调)函数来遍历jQuery对象本身,因为这很自然。jQuery。每个(对象,回调)实用程序函数迭代对象和数组。在很长一段时间里,除了不同的语法之外,我不知道它能做什么(我不介意写所有时髦的循环),我有点惭愧,直到最近我才意识到它的主要优点。

问题是,自从jQuery的循环体。每个(对象,回调)是一个函数,每次在循环中都获得一个新的作用域,这在循环中创建闭包时尤其方便。

换句话说,一个典型的常见错误是这样做的:

var functions = [];
var someArray = [1, 2, 3];
for (var i = 0; i < someArray.length; i++) {
    functions.push(function() { alert(someArray[i]) });
}

现在,当您调用函数数组中的函数时,您将得到三次警报,内容为undefined,这很可能不是您想要的。问题是只有一个变量i,而所有三个闭包都指向它。当循环结束时,i的最终值是3,somearray[3]是未定义的。你可以通过调用另一个函数来为你创建闭包。或者你使用jQuery实用工具,它基本上会为你做:

var functions = [];
var someArray = [1, 2, 3];
$.each(someArray, function(item) {
    functions.push(function() { alert(item) });
});

现在,当您调用这些函数时,您将得到三个内容为1、2和3的警报。

一般来说,没有什么是你自己不能做的,但拥有它是很好的。

实时事件处理程序

为任何匹配选择器的元素设置一个事件处理程序,即使它在初始页面加载后被添加到DOM:

$('button.someClass').live('click', someFunction);

这允许您通过ajax加载内容,或通过javascript添加内容,并自动为这些元素正确设置事件处理程序。

同样地,要停止实时事件处理:

$('button.someClass').die('click', someFunction);

与常规事件相比,这些实时事件处理程序有一些限制,但它们在大多数情况下工作得很好。

要了解更多信息,请参阅jQuery文档。

更新:live()和die()在jQuery 1.7中已弃用。参见http://api.jquery.com/on/和http://api.jquery.com/off/了解类似的替换功能。

UPDATE2: live()早在jQuery 1.7之前就已经弃用了。对于1.7之前的jQuery 1.4.2+版本,请使用delegate()和undelegate()。live()示例($('button.someClass')。live('click', someFunction);)可以像这样使用delegate()重写:$(document).delegate('button.someClass', 'click', someFunction);

从更基本、更高级的角度来看,您可以尝试通过编写自己的小框架来模拟jQuery的基本选择器机制(实际操作比听起来简单)。它不仅会不断地改进你的Javascript,还会帮助你理解为什么jQuery的$("#elementId")比$(". elementclass ")快很多倍,也比$("element#elementId")快很多倍(这可能在表面上与直觉相反)。

这也将迫使你学习面向对象的Javascript,这将帮助你以一种更模块化的方式组织你的代码,从而避免沉重的jQuery脚本块所带来的意大利面条式的代码性质。

说到技巧和技巧,以及一些教程。我发现Jeffery Way的这些系列教程(“jQuery绝对初学者”视频系列)非常有用。

它针对那些刚接触jQuery的开发人员。他展示了如何用jQuery创建许多很酷的东西,比如动画,创建和删除元素等…

我从中学到了很多。他展示了如何简单地使用jQuery。 现在我喜欢它,我可以阅读和理解任何jQuery脚本,即使它很复杂。

这里有一个我喜欢的例子“调整文本大小”

1 - jQuery……

<script language="javascript" type="text/javascript">
    $(function() {
        $('a').click(function() {
            var originalSize = $('p').css('font-size'); // get the font size 
            var number = parseFloat(originalSize, 10); // that method will chop off any integer from the specified variable "originalSize"
            var unitOfMeasure = originalSize.slice(-2);// store the unit of measure, Pixle or Inch

            $('p').css('font-size', number / 1.2 + unitOfMeasure);
            if(this.id == 'larger'){$('p').css('font-size', number * 1.2 + unitOfMeasure);}// figure out which element is triggered
         });        
     });
</script>

2- CSS样式…

<style type="text/css" >
body{ margin-left:300px;text-align:center; width:700px; background-color:#666666;}
.box {width:500px; text-align:justify; padding:5px; font-family:verdana; font-size:11px; color:#0033FF; background-color:#FFFFCC;}
</style>

2 - HTML……

<div class="box">
    <a href="#" id="larger">Larger</a> | 
    <a href="#" id="Smaller">Smaller</a>
    <p>
    In today’s video tutorial, I’ll show you how to resize text every time an associated anchor tag is clicked. We’ll be examining the “slice”, “parseFloat”, and “CSS” Javascript/jQuery methods. 
    </p>
</div>

强烈推荐这些教程…

http://blog.themeforest.net/screencasts/jquery-for-absolute-beginners-video-series/