$(document).ready(function(){ jQuery.fn.center=function(){this.css("position","absolute");this.css("top",( $(window).height()-this.height())/2+$(window).scrollTop()+"px");this.css("left",( $(window).width()-this.width())/2+$(window).scrollLeft()+"px");returnthis;} $("#id").center();});
20、创建自己的选择器
$(document).ready(function(){ $.extend($.expr[':'],{ moreThen1000px:function(a){return $(a).width()>1000;}}); $('.box:moreThen1000px').click(function(){// creating a simple js alert box alert('The element that you have clicked is over 1000 pixels wide');});});
21、计算元素的数目
$(document).ready(function(){ $("p").size();});
22、设置自己的li样式
$(document).ready(function(){ $("ul").addClass("Replaced"); $("ul > li").prepend(" ");// how to use ul.Replaced{ list-style : none;}});
23、使用google的主机来加载jquery库
<script src="http://www.google.com/jsapi"></script> <script type="text/javascript"> google.load("jquery", "1.2.6"); google.setOnLoadCallback(function() { // do something }); </script><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js" type="text/javascript"></script> // Example 2:(the best and fastest way) <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>
24、关闭jquery动画效果
$(document).ready(function(){ jQuery.fx.off=true;});
25、使用自己的jquery标识
$(document).ready(function(){var $jq = jQuery.noConflict(); $jq('#id').show();});