/**1.毕包*/(function($){ /**2.插件*/ $.fn.myaccordion=function(opts){ var settings=$.extend({ selectedClz:"navSelected", titleTagName:"h3" },opts||{}); var titleNode=$(this).find("ul>"+settings.titleTagName); var selectedNode=$(this).find("ul."+settings.selectedClz+">" +settings.titleTagName); titleNode.css("cursor","pointer"); titleNode.nextAll().css("display","none"); selectedNode.nextAll().css("display","block"); titleNode.click(function(){ var checked=$(this).parent().hasClass(settings.selectedClz); if(checked){ $(this).parent().removeClass(settings.selectedClz); //$(this).nextAll().css("display","none"); $(this).nextAll().slideUp(); }else{ $(this).parent().addClass(settings.selectedClz); //$(this).nextAll().css("display","block"); $(this).nextAll().slideDown(); } }); }; $.fn.trColorChange=function(opts){ var settings=$.extend({ overClz:"trMouseover", evenClz:"trEvenColor" },opts||{}); $(this).find("tbody tr:even").addClass(settings.evenClz); $(this).find("tbody tr").on("mouseenter mouseleave",function(){ $(this).toggleClass(settings.overClz); }); }; $.fn.confirmOperator=function(opts){ var settings=$.extend({ msg:"该操作不可逆,请确认操作!", eventName:"click" },opts||{}); $(this).on(settings.eventName,function(event){ if(!confirm(settings.msg)){ //取消,将事件阻止 event.preventDefault(); } }); };})(jQuery)外部调用(function($){ $(function(){ $("#listTable").trColorChange(); $("a.delete").confirmOperator(); });})(jQuery)