checkBox全选实现
<!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" src="../Day26/doctool.js"></script><script type="text/javascript">//1,获取被选中的checkbox,通过checked属性的状态完成。//2,获取被选择checkbox的value的金额。//3,求和。//4,定义span区域存储总金额。function getSum(){var items = byName("item");var sum = 0;for(var x=0;x<items.length; x++){if(items[x].checked)sum += parseInt(items[x].value);}var spanNode = byId("sum");var str = sum+"元";spanNode.innerHTML = str.fontsize(7);}function checkAll(index){var allNode = byName("all")[index];var items = byName("item");for(var x=0;x<items.length; x++){items[x].checked = allNode.checked;}}</script></head><body><input type="checkbox" name="all" onclick="checkAll(0)" />全选<br /><input type="checkbox" name="item" value="3000" />笔记本电脑:3000元<br /><input type="checkbox" name="item" value="3000" />笔记本电脑:3000元<br /><input type="checkbox" name="item" value="3000" />笔记本电脑:3000元<br /><input type="checkbox" name="item" value="3000" />笔记本电脑:3000元<br /><input type="checkbox" name="item" value="3000" />笔记本电脑:3000元<br /><input type="checkbox" name="item" value="3000" />笔记本电脑:3000元<br /><input type="checkbox" name="item" value="3000" />笔记本电脑:3000元<br /><input type="checkbox" name="item" value="3000" />笔记本电脑:3000元<br /><input type="checkbox" name="all" onclick="checkAll(1)" />全选<br /><input type="button" value="获取总金额" onclick="getSum()" /><span id="sum"></span></body></html>
?