js实现复选框的全选和反选效果
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<script type="text/javascript">
window.onload = function(){
var ck = document.getElementById('ck');
var btn = document.getElementById('btn');
var on = false;
btn.onclick = function(){
if(on){
ck.checked = on;
btn.innerHTML = '反选';
}else{
ck.checked = on;
btn.innerHTML = '全选';
}
on = !on
}
}
</script>
</head>
<body>
<input type="checkbox" name="" id="ck" value="" checked/>
<button type="button" id="btn">反选</button>
</body>
</html>
本文来自博客园,作者:JackieDYH,转载请注明原文链接:https://www.cnblogs.com/JackieDYH/p/17634854.html