js全选反选动态创建标签
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script type="text/javascript"> //动态创建图片 function createPic() { var div = document.getElementById("divpic"); var imgs = document.createElement("img"); imgs.setAttribute("src", "1.bmp"); div.appendChild(imgs); }; //选择所有的checkbox function checkall() { var div = document.getElementById("divcheck"); var input = div.getElementsByTagName("input"); for (var i = 0; i < input.length ; i++) { if (input[i].type == "checkbox") { input[i].checked = true; } } } //反选所有的checkbox function uncheckall() { var div = document.getElementById("divcheck"); var input = div.getElementsByTagName("input"); for (var i = 0; i < input.length; i++) { if (input[i].type == "checkbox") { input[i].checked = false; } } } </script> </head> <body onload="createPic()"> <form id="form1" runat="server"> <div id="divpic"> </div> <button onclick="checkall();return false;" >全选</button> <button onclick="uncheckall();return false;">反选</button> <div id="divcheck"> <input type="checkbox" />1 <input type="checkbox" />2 <input type="checkbox" />3 </div> </form> </body> </html>