亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關于checkbox復選框的問題?還是有一些問題想了解,麻煩幫忙看看下面的內容

關于checkbox復選框的問題?還是有一些問題想了解,麻煩幫忙看看下面的內容

牛魔王的故事 2021-06-20 17:10:02
假設有8個checkbox復選框從集合里讀取到的 比如要勾第5個checkbox 前面4個全部勾上 勾第8個前面七個全部勾上 JS要怎么寫呢
查看完整描述

2 回答

?
大話西游666

TA貢獻1817條經驗 獲得超14個贊

<input type="checkbox" data-index="1" class="chexkbox">選項1<input type="checkbox" data-index="2" class="chexkbox">選項2<input type="checkbox" data-index="3" class="chexkbox">選項3<input type="checkbox" data-index="4" class="chexkbox">選項4<input type="checkbox" data-index="5" class="chexkbox">選項5<input type="checkbox" data-index="6" class="chexkbox">選項6<input type="checkbox" data-index="7" class="chexkbox">選項7<input type="checkbox" data-index="8" class="chexkbox">選項8<input type="checkbox" data-index="9" class="chexkbox">選項9<input type="checkbox" data-index="10" class="chexkbox">選項10<script>var checkboxArr = document.getElementsByClassName('chexkbox');for(var i = 0; i < checkboxArr.length; i ++){    checkboxArr[i].onclick = function(){        var index = this.getAttribute('data-index');        for(var c = 0; c < index; c ++){            if(this.checked == true){                checkboxArr[c].checked = true;            }else{                checkboxArr[c].checked = false;            }        }             }}</script>

查看完整回答
反對 回復 2021-06-26
?
慕的地10843

TA貢獻1785條經驗 獲得超8個贊

用jquery寫的。用到了jquery的prevAll()方法。

$(".input").click(function(){//這個input是我給checkbox取的共有類名

$(this).prevAll().attr("checked",true);

})


查看完整回答
反對 回復 2021-06-26
  • 2 回答
  • 0 關注
  • 490 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號