JQuery全选与取消插件时间:2022-12-03 00:07:50自己参考了网上的代码写了一个全选与取消插件,代码如下: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>JQuery实现全选与取消</title><mce:script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" mce_src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></mce:script><mce:script language="javascript" src="checkall.js" mce_src="checkall.js"></mce:script><mce:script language="javascript"><!--$(document).ready(function(){$("#checkall").checkall({chname:"checkname[]"}); });// --></mce:script></head><body><div><form><input type='checkbox' id='id1' name='checkname[]' value='1' />value1 <input type='checkbox' id='id2' name='checkname[]' value='2' />value2 <input type='checkbox' id='id3' name='checkname[]' value='3' />value3 <input type='checkbox' id="checkall" name="checkall" />全选</form></div></body></html> checkall.js代码如下: (function($) { $.fn.checkall = function(options) {var defaults = {chname:"checkname[]"};var options = $.extend(defaults, options);this.click(function(){if(this.checked){$("input[name='"+options.chname+"']").attr("checked",true);}else{$("input[name='"+options.chname+"']").attr("checked",false);}});}})(jQuery);