日期:2014-05-16 浏览次数:20453 次
<!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>无标题文档</title> <script type="text/javascript"> window.onload = function() { document.getElementById('btn').onclick = function() { var obj = document.getElementsByTagName('input'); //获取文档中所有的input元素 for (var i = 0; i < obj.length; i ++) { if (obj[i].type == 'checkbox') { obj[i].checked = true; //设置复选框元素对象的checked属性值为true就能勾选该复选框;false即为取消选择 } } } } </script> </head> <body> <form> <input type="checkbox" />1<br /> <input type="checkbox" />2<br /> <input type="button" id="btn" value="全选" /> </form> </body> </html>