jquery ajax实例代码_jquery常用代码总结

时间:2021-09-29 00:00:00 工作总结
图片预加载:(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");新窗口打开链接$("a[@rel$="external"]").click(function(){     this.target = "_blank";});/*   Usage:   www.fanwen112.com*/平滑滚动$(document).ready(function() {$("a.topLink").click(function() {$("html, body").animate({scrollTop: $($(this).attr("href")).offset().top + "px"}, {duration: 500,easing: "swing"});return false;});});鼠标划入时渐入渐出$(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    });});等高的列var max_height = 0;$("div.col").each(function(){    if ($(this).height() > max_height) { max_height = $(this).height(); }});$("div.col").height(max_height);老版本浏览器html5支持(function(){    if(!/*@[email protected]*/0)        return;    var e = "abbr,article,aside,audio,bb,canvas,datagrid,datalist,details,dialog,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(","),i=e.length;while(i--){document.createElement(e[i])}})()//然后在head中引入该js测试浏览器是否支持css3var supports = (function() {   var div = document.createElement("div"),      vendors = "Khtml Ms O Moz Webkit".split(" "),      len = vendors.length;   return function(prop) {      if ( prop in div.style ) return true;      prop = prop.replace(/^[a-z]/, function(val) {         return val.toUpperCase();      });      while(len--) {         if ( vendors[len] + prop in div.style ) {            // browser supports box-shadow. Do what you need.            // Or use a bang (!) to test if the browser doesn"t.            return true;         }      }      return false;   };})();if ( supports("textShadow") ) {   document.documentElement.className += " textShadow";取得url中的参数$.urlParam = function(name){var results = new RegExp("[?&]" + name + "=([^&#]*)").exec(window.location.href);if (!results) { return 0; }return results[1] || 0;}禁用回车提交表单$("#form").keypress(function(e) {  if (e.which == 13) {    return false;  }});