<div class="codetitle"> <span><a style="CURSOR: pointer" data="59043" class="copybut" id="copybut59043" onclick="doCopy('code59043')"><u>复制代码</u></a></span> 代码如下:</div> <div class="codebody" id="code59043"> <br> <br> <br> <br><meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <br><style type="text/css"> <BR>#newsTable{margin:100px auto;} <BR></style> <br><script language="javascript" type="text/javascript" src="jquery1.1.2.js"></script> <br><script language="javascript" type="text/javascript"> <BR>//阿会楠练习 2009-4-13 <BR>$(document).ready(function(){ <BR>$("#btnOk").click(function(){ <BR>this.value = this.value == "全选"?"反选":"全选"; <BR>$("input[@type='checkbox']").checkCbx(); <BR>}); <BR>}); <BR>//当你的代码出现each时,你应该重写上面的代码来构造一个插件,jquery教程中的一句话 <BR>$.fn.checkCbx = function(){ <BR>return this.each(function(){ <BR>this.checked = !this.checked; <BR>}); <BR>} <BR></script> <br><title>无标题文档</title> <br> <br><br> <br><table border="1" id="newsTable"> <br><tr> <br><th>选择</th> <br><th>Id</th> <br><th>作者</th> <br> </tr> <br><tr> <br><td><input type="checkbox" name="cbx"></td> <br><td>1</td> <br><td>阿会楠</td> <br> </tr> <br><tr> <br><td><input type="checkbox" name="cbx"></td> <br><td>2</td> <br><td>阿会楠</td> <br> </tr> <br><tr> <br><td><input type="checkbox" name="cbx"></td> <br><td>3</td> <br><td>阿会楠</td> <br> </tr> <br><tr> <br><td><input type="checkbox" name="cbx"></td> <br><td>4</td> <br><td>阿会楠</td> <br> </tr> <br><tr> <br><td><input type="checkbox" name="cbx"></td> <br><td>5</td> <br><td>阿会楠</td> <br> </tr> <br><tr> <br><td><input type="checkbox" name="cbx"></td> <br><td>6</td> <br><td>阿会楠</td> <br> </tr> <br><tr> <br><td colspan="3"><input type="button" name="btnOk" id="btnOk" value="全选"></td> <br> </tr> <br> </table> <br> <br><br> </div>