亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

用原生JS實(shí)現(xiàn)簡(jiǎn)單的多選框功能

 更新時(shí)間:2017年06月12日 16:13:26   作者:碼農(nóng)的N次方  
這篇文章主要介紹了用原生JS實(shí)現(xiàn)簡(jiǎn)單的多選框功能,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下

廢話不多說了,直接給大家貼代碼了,具體代碼如下所示:

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>無標(biāo)題文檔</title>
</head>
<body>
<input id="cheakAll" type="checkbox">全選
<div>
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
<input type="checkbox">
</div>
</body>
</html>
<script>
//找到全選按鈕
var oChkAllBtn=document.getElementById('cheakAll');
var oDiv=document.getElementsByTagName('div')[0];
var aInput=oDiv.getElementsByTagName('input');
var n=0; //計(jì)數(shù)器
//alert(aInput.length);
//點(diǎn)擊全選按鈕,讓其他的全部選中
oChkAllBtn.onclick=function(){
//判斷我是什么狀態(tài)
/*if(this.checked==true){
for(var i=0; i<aInput.length; i++){
aInput[i].checked=true;
}
}else{
for(var i=0; i<aInput.length; i++){
aInput[i].checked=false;
}
}*/
for(var i=0; i<aInput.length; i++){
if(this.checked==true){//判斷全選按鈕自己的狀態(tài)
aInput[i].checked=true;
n=aInput.length; //控制計(jì)數(shù)器
}else{
aInput[i].checked=false;
n=0; //控制計(jì)數(shù)器
}
};
};
//--------------------------------------------
//每一個(gè)按鈕綁定事件
for(var j=0; j<aInput.length; j++){
aInput[j].onclick=function(){
//如果我自己是cheaked狀態(tài) n++ 否則 n--
if(this.checked==true){
n++;
}else{
n--;
};
//console.log(n);
//如果n==aInput.length
if(n==aInput.length){
oChkAllBtn.checked=true;
}else{
oChkAllBtn.checked=false;
}
};
};
</script>

以上所述是小編給大家介紹的用原生JS實(shí)現(xiàn)簡(jiǎn)單的多選框功能,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

最新評(píng)論