1.预加载图片

GDScript3
12 行
(function($) {
  var cache = [];
  // Arguments are image paths relative to the current page.
  $.preLoadImages = function() {
    var args_len = arguments.length;
    for (var i = args_len; i--;) {
      var cacheImage = document.createElement('img');
      cacheImage.src = arguments[i];
      cache.push(cacheImage);
    }
  }
jQuery.preLoadImages("image1.gif", "/path/to/image2.png");

2. 让页面中的每个元素都适合在移动设备上展示

GDScript3
11 行
var scr = document.createElement('script');
scr.setAttribute('src', 'https://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js');
document.body.appendChild(scr);
scr.onload = function(){
        $('div').attr('class', '').attr('id', '').css({
                'margin' : 0,
                'padding' : 0,
                'width': '100%',
                'clear':'both'
        });
};

3.图像等比例缩放

4.返回页面顶部

代码片段
8 行
// Back To Top
$(document).ready(function(){ 
  $('.top').click(function() {  
     $(document).scrollTo(0,500);  
  });
}); 
//Create a link defined with the class .top
<a href="#" class="top">Back To Top</a>

5.使用jQuery打造手风琴式的折叠效果

6.通过预加载图片廊中的上一幅下一幅图片来模仿Facebook的图片展示方式

GDScript3
8 行
var nextimage = "/images/some-image.jpg";
$(document).ready(function(){
window.setTimeout(function(){
var img = $("").attr("src", nextimage).load(function(){
//all done
});
}, 100);
});

7.使用jQuery和Ajax自动填充选择框

8.自动替换丢失的图片

JavaScript
8 行
// Safe Snippet
$("img").error(function () {
        $(this).unbind("error").attr("src", "missing_image.gif");
});
// Persistent Snipper
$("img").error(function () {
        $(this).attr("src", "missing_image.gif");
});

9.在鼠标悬停时显示淡入/淡出特效

GDScript3
8 行
$(document).ready(function(){
    $(".thumbs img").fadeTo("slow", 0.6); // This sets the opacity of the thumbs to fade down to 60% when the page loads
    $(".thumbs img").hover(function(){
        $(this).fadeTo("slow", 1.0); // This should set the opacity to 100% on hover
    },function(){
        $(this).fadeTo("slow", 0.6); // This should set the opacity back to 60% on mouseout
    });
});

10.清空表单数据

11.预防对表单进行多次提交

12.动态添加表单元素

代码片段
5 行
//change event on password1 field to prompt new input
$('#password1').change(function() {
        //dynamically create new input and insert after password1
        $("#password1").append("");
});

13.让整个Div可点击

代码片段
2 行
blah blah blah. link
The following lines of jQuery will make the entire div clickable: $(".myBox").click(function(){ window.location=$(this).find("a").attr("href"); return false; }); 

14.平衡高度或Div元素

GDScript3
5 行
var maxHeight = 0;
$("div").each(function(){
   if ($(this).height() > maxHeight) { maxHeight = $(this).height(); }
});
$("div").height(maxHeight);

15. 在窗口滚动时自动加载内容