js仿百度音樂(lè)全選操作

本文實(shí)例為大家分享了js全選操作的具體代碼,供大家參考,具體內(nèi)容如下

創(chuàng)新互聯(lián)建站專(zhuān)注于網(wǎng)站制作、網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)、網(wǎng)站制作、網(wǎng)站開(kāi)發(fā)。公司秉持“客戶(hù)至上,用心服務(wù)”的宗旨,從客戶(hù)的利益和觀點(diǎn)出發(fā),讓客戶(hù)在網(wǎng)絡(luò)營(yíng)銷(xiāo)中找到自己的駐足之地。尊重和關(guān)懷每一位客戶(hù),用嚴(yán)謹(jǐn)?shù)膽B(tài)度對(duì)待客戶(hù),用專(zhuān)業(yè)的服務(wù)創(chuàng)造價(jià)值,成為客戶(hù)值得信賴(lài)的朋友,為客戶(hù)解除后顧之憂(yōu)。

js仿百度音樂(lè)全選操作

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無(wú)標(biāo)題文檔</title>
<style>
*{margin:0;padding:0;}
ul{list-style:none;}
#content{width:300px;border:1px solid #ccc;margin:20px auto;}
#content ul{width:300px;}
#content ul li,#content div{width:300px;height:50px;line-height:50px;border-bottom:1px dotted #ccc;text-indent:20px;}
#content ul li:nth-child(odd) {background:#f1f1f1;}
#content ul li.active,#content ul li:hover{background:#99FFCC;}
</style>
<script>
window.onload = function () {
  var oDiv = document.getElementById('content');
  var checkAll = document.getElementById('checkAll');
  var aLi = oDiv.getElementsByTagName('li');
  var aInput = oDiv.getElementsByTagName('input');


  for ( var i = 0; i < aInput.length; i++ ) {
    aInput[i].index = i;
    aInput[i].onclick = function () {
      aLi[this.index].className = this.checked ? 'active' : '';
    }
  }

  checkAll.onclick = function () {
    for ( var i = 0; i < aInput.length; i++ ) {
      if(!aInput[i].checked) aInput[i].checked = true;
      aLi[i].className = 'active';
    }
  }
}
</script>
</head>

<body>
<div id="content">
  <ul>
    <li>
      <input type="checkbox"/>
      <span>私奔</span>
      <span>梁博</span>
    </li>
    <li>
      <input type="checkbox"/>
      <span>北京</span>
      <span>杜甫</span>
    </li>
    <li>
      <input type="checkbox"/>
      <span>花人</span>
      <span>李白</span>
    </li>
    <li>
      <input type="checkbox"/>
      <span>神話</span>
      <span>光良</span>
    </li>
    <li>
      <input type="checkbox"/>
      <span>神話</span>
      <span>光良</span>
    </li>
    <li>
      <input type="checkbox"/>
      <span>神話</span>
      <span>光良</span>
    </li>
    <li>
      <input type="checkbox"/>
      <span>神話</span>
      <span>光良</span>
    </li>
    <li>
      <input type="checkbox"/>
      <span>神話</span>
      <span>光良</span>
    </li>
    <li>
      <input type="checkbox"/>
      <span>神話</span>
      <span>光良</span>
    </li>
  </ul>
  <div>
    <input id="checkAll" type="checkbox" />全選
  </div>
</div>
</body>
</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持創(chuàng)新互聯(lián)。

本文名稱(chēng):js仿百度音樂(lè)全選操作
網(wǎng)站鏈接:http://www.muchs.cn/article14/ihehge.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供企業(yè)建站網(wǎng)站營(yíng)銷(xiāo)、自適應(yīng)網(wǎng)站服務(wù)器托管、Google、網(wǎng)站導(dǎo)航

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

h5響應(yīng)式網(wǎng)站建設(shè)