jquery常用代码段

来源:互联网 发布:忻州网络第一传媒 编辑:程序博客网 时间:2024/06/07 06:05

(1)内容过滤

 $("#filtername").keyup(function(){            $("table tbody tr").hide().filter(":contains('"+($(this).val)+"')").show();            })


(2)tab切换

var $div_li=$("div.tab_box ul li");            $div_li.click(function(){            $(this).addClass("selected").siblings().removeClass("selected");            var index=$div_li.index(this);            $('div.tab_box>div').eq(index).show().siblings().hide();            })

(3)网页换肤



(4)插件写法

封装对象方法的插件 jQuery,fn.extend()

封装全局函数的插件 jQuery.extend()

选择器插件 jQuery.extend()

jQuery.extend()还可以扩展已有的object对象

jQuery.extend(settings,options)

;(function($){$.fn.extend({"color":function(value){if(value==undefined){return this.css("color");}else{return this.css("color",value);}}})})(jQuery);




0 0