用JAVASCRIPT编写代码
发布网友
发布时间:2023-12-18 21:55
我来回答
共2个回答
热心网友
时间:2024-07-16 10:29
function selectAll(){//全选
var obj = document.listform.elements;//listform是form的name="listform"
for (var i=0;i<obj.length;i++){
if (obj[i].name == "delid"){//delid是checkbook的name="delid",你可以随便起名字
obj[i].checked = true;
}
}
}
function unselectAll(){
var obj = document.listform.elements;//全不选
for (var i=0;i<obj.length;i++){
if (obj[i].name == "delid"){
if (obj[i].checked==true) obj[i].checked = false;
else obj[i].checked = true;
}
}
}
热心网友
时间:2024-07-16 10:29
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style type="text/css">
li{ width:200px; margin:20px 0;}
</style>
<script data-a="a"></script>
<script type="text/javascript">
window.onload =function(){
var submit = document.getElementById("submit");
var chks = document.getElementsByName("peijian");
submit.onclick = function(){
if(submit.innerHTML == "全部需要"){
for(var i =0;i<chks.length;i++){
chks[i].checked=true;
}
submit.innerHTML="全部不需要";
}else{
for(var i = 0;i<chks.length;i++){
chks[i].checked= false;
}
submit.innerHTML ="全部需要";
}
};
}
</script>
</head>
<body>
<table width="200" border="1" cellspacing="0" cellpadding="0">
<tr>
<td><input type="checkbox" name="peijian" id="subiao"/>鼠标</td>
</tr>
<tr>
<td><input type="checkbox" name="peijian"/>鼠标</td>
</tr>
<tr>
<td><input type="checkbox" name="peijian"/>鼠标</td>
</tr>
<tr>
<td><input type="checkbox" name="peijian"/>鼠标</td>
</tr>
<tr>
<td><input type="checkbox" name="peijian"/>鼠标</td>
</tr>
<tr>
<td><a href="#" id="submit">全部需要</a></td>
</tr>
</table>
</body>
</html>
本人也是新手,不知道这样行不行
追问谢谢帮助,只是只能采纳一个问题,这个回答对我很有帮助