dojo的checkbox全選和取值

來源:互聯網
上載者:User

最近項目需要用dojo,有個應用是有多個checkbox。選中一個一級目錄的checkbox,二級所有會選中。

我用以前常用的js全選,(document.getElementById('chkname').checked=true;)發現沒用反應。

後來通過F12查看html,才發現問題。其實已經選中了,只是dojo的checkbox藍色選中樣式沒加上去,就是說只能用dojo方式設定checkbox的選擇狀態。

發現在dojo下,input類型為checkbox的控制項無法通過dojo方式綁定click,onchange事件。

 <input type="checkbox" data-dojo-type="dijit/form/CheckBox" id="w01" name="w01" onchange="btnClick('w01',2)"     value="w01">     <label for="w01">w01 input/checkbox dijit/form/CheckBox</label>        <input type="checkbox" data-dojo-type="dijit/form/CheckBox" id="w01_0" value="1">    <input type="checkbox" data-dojo-type="dijit/form/CheckBox" id="w01_1" value="2">        <input type="checkbox" data-dojo-type="dijit/form/CheckBox" id="w02" name="w02" onchange="btnClick('w02',3)"     value="w01">     <label for="w01">w01 input/checkbox dijit/form/CheckBox</label>        <input type="checkbox" data-dojo-type="dijit/form/CheckBox" id="w02_0" value="1">    <input type="checkbox" data-dojo-type="dijit/form/CheckBox" id="w02_1" value="2">     <input type="checkbox" data-dojo-type="dijit/form/CheckBox" id="w02_1" value="3">     </br>     <input type="button" value='show' onclick="showlist('w01',2)"/>     <label for="w01">sub</label><script type="text/javascript">        function btnClick(a,size) {        for(i=0;i<size;i++)        dijit.byId(a+'_'+i).attr('checked',dijit.byId(a).checked);        }              function showlist(a,size){      s='';      for(i=0;i<size;i++){      if(dijit.byId(a+'_'+i).checked){      s+=dijit.byId(a+'_'+i).value+',';      }      }      alert(s)      }    </script>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.