JS+JSP checkBox 全选具体实现

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

JS+JSP checkBox 全选具体实现

  2020-05-13 我要评论
复制代码 代码如下:

<script>
function func(){
var options=document.getElementsByName("chkBox");
for (var i=0;i<options.length;i++){
if(!options[i].disabled){
options[i].checked=true;
}
}
}
</script>
<input type=checkbox name=chkBox value=1 disabled>
<input type=checkbox name=chkBox value=1>
<input type=checkbox name=chkBox value=1>
<input type=checkbox name=chkBox value=1>
<input type=button value="测 试" onclick="func()">

用javascript吧。
复制代码 代码如下:

<html>
<body>
<script>
function kk(){
var handleEl = document.getElementById("kkHandler");
var els = document.getElementsByName("kk");
for(i=0;i<els.length;i++){
els[i].checked = handleEl.checked;
}

}
</script>
<input type=checkbox onclick="kk()" name="kkHandler">全选<br>
<input type=checkbox name="kk">
<input type=checkbox name="kk">
</body>
</html>

2:
复制代码 代码如下:

<form name="form" ID="Form1">
<input type="checkbox" name="id" value="" ID="Checkbox1">1
<input type="checkbox" name="id" value="" ID="Checkbox2">2
<input type="checkbox" name="chose" value="" onclick="selectAll()" ID="Checkbox5">allselect
</form>
<script>
function selectAll()
{
if(!document.form.id.length){
if(document.form.chose.checked){
document.form.id.checked=true;
}
else{
document.form.id.checked=false;
}
}
else{
for(var i=0;i<document.form.id.length;i++){
if(document.form.chose.checked){
document.form.id[i].checked=true;
}
else{
document.form.id[i].checked=false;
}
}
}
}
</script>

3:
复制代码 代码如下:

<input type='checkbox' name='info' value='a'>
<input type='checkbox' name='info' value='b'>
<input type='checkbox' name='info' value='c'>
<input type='checkbox' name='info' value='d'>
<input type='checkbox' name='info' value='e'><br>
<input type='button' value =' 全选 'onclick='check_all();'>
<script>
function check_all(){
arr = document.getElementsByName('info');
for(i=0;i<arr.length;i++){
arr[i].checked = true;
}
}
</script>

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们