我试图在这里找到类似问题的解决方案,但没有一个解决方案能解决我的问题。我当前在取消选中所有复选框时禁用提交按钮时出现问题。
基本上我的网站有几个复选框,当用户勾选任何复选框时,禁用的提交按钮将能够提交。但是当用户取消选中该复选框时,我的提交按钮不会被禁用。
以下是我的示例HTML代码:
<form action="" id="myform" name="myform" class="myform">
<div class="anchor">
<ul>
<li>
<label><input type="checkbox" data-id="All Master" data-name="All Master" id="myCheckBox0" onchange="checkDisabled(testing);"/> All Kedai Kiosk On Master Mode</label>
<ul>
<li>
<label><input type="checkbox" data-id="Selangor" data-name="Selangor" id="myCheckBox1" onchange="checkDisabled(testing);"/> Selangor</label>
<ul id="navlist">
<li><label><input type="checkbox" data-id="Petaling Jaya" data-name="Petaling Jaya" id="myCheckBox2" onchange="checkDisabled(testing);"/> Petaling Jaya </label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="1" data-id="Kiosk 1" data-name="Kiosk 1" id="myCheckBox3" onchange="checkDisabled(testing);"/> Kiosk 1 </label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Puchong" data-name="Puchong" id="myCheckBox4" onchange="checkDisabled(testing);"/> Puchong </label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="2" data-id="Kiosk 2" data-name="Kiosk 2" id="myCheckBox5" onchange="checkDisabled(testing);"/> Kiosk 2 </label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Subang Hub" data-name="Subang Hub" id="myCheckBox6" onchange="checkDisabled(testing);"/> Subang Hub </label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="5" data-id="Kiosk 5" data-name="Kiosk 5" id="myCheckBox7" onchange="checkDisabled(testing);"/> Kiosk 5 </label></li>
<li><label><input type="checkbox" name="kioskMaster[]" value="20" data-id="Kiosk 20" data-name="Kiosk 20" id="myCheckBox8" onchange="checkDisabled(testing);"/> Kiosk 20 </label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Bangi" data-name="Bangi" id="myCheckBox9" onchange="checkDisabled(testing);"/> Bangi </label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="7" data-id="Kiosk 7" data-name="Kiosk 7" id="myCheckBox10" onchange="checkDisabled(testing);"/> Kiosk 7 </label></li>
<li><label><input type="checkbox" name="kioskMaster[]" value="8" data-id="Kiosk 8" data-name="Kiosk 8" id="myCheckBox11" onchange="checkDisabled(testing);"/> Kiosk 8 </label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Shah Alam" data-name="Shah Alam" id="myCheckBox12" onchange="checkDisabled(testing);"/> Shah Alam </label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="9" data-id="Kiosk 9" data-name="Kiosk 9" id="myCheckBox13" onchange="checkDisabled(testing);"/> Kiosk 9 </label></li>
<li><label><input type="checkbox" name="kioskMaster[]" value="10" data-id="Kiosk 10" data-name="Kiosk 10" id="myCheckBox14" onchange="checkDisabled(testing);"/> Kiosk 10 </label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Cheras" data-name="Cheras" id="myCheckBox15" onchange="checkDisabled(testing);"/> Cheras </label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="11" data-id="Kiosk 11" data-name="Kiosk 11" id="myCheckBox16" onchange="checkDisabled(testing);"/> Kiosk 11 </label></li>
<li><label><input type="checkbox" name="kioskMaster[]" value="12" data-id="Kiosk 12" data-name="Kiosk 12" id="myCheckBox17" onchange="checkDisabled(testing);"/> Kiosk 12 </label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Banting" data-name="Banting" id="myCheckBox18" onchange="checkDisabled(testing);"/> Banting</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="13" data-id="Kiosk 13" data-name="Kiosk 13" id="myCheckBox19" onchange="checkDisabled(testing);"/> Kiosk 13 </label></li>
<li><label><input type="checkbox" name="kioskMaster[]" value="14" data-id="Kiosk 14" data-name="Kiosk 14" id="myCheckBox20" onchange="checkDisabled(testing);"/> Kiosk 14 </label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Rawang" data-name="Rawang" id="myCheckBox21" onchange="checkDisabled(testing);"/> Rawang</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="15" data-id="Kiosk 15" data-name="Kiosk 15" id="myCheckBox22" onchange="checkDisabled(testing);"/> Kiosk 15 </label></li>
<li><label><input type="checkbox" name="kioskMaster[]" value="16" data-id="Kiosk 16" data-name="Kiosk 16" id="myCheckBox23" onchange="checkDisabled(testing);"/> Kiosk 16 </label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Pelabuhan Klang" data-name="Pelabuhan Klang" id="myCheckBox24" onchange="checkDisabled(testing);"/> Pelabuhan Klang</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="17" data-id="Kiosk 17" data-name="Kiosk 17" id="myCheckBox25" onchange="checkDisabled(testing);"/> Kiosk 17 </label></li>
<li><label><input type="checkbox" name="kioskMaster[]" value="18" data-id="Kiosk 18" data-name="Kiosk 18" id="myCheckBox26" onchange="checkDisabled(testing);"/> Kiosk 18 </label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Sungai Besar" data-name="Sungai Besar" id="myCheckBox27" onchange="checkDisabled(testing);"/> Sungai Besar</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="19" data-id="Kiosk 19" data-name="Kiosk 19" id="myCheckBox28" onchange="checkDisabled(testing);"/> Kiosk 19 </label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Kuala Selangor" data-name="Kuala Selangor" id="myCheckBox29" onchange="checkDisabled(testing);"/> Kuala Selangor</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="21" data-id="Kiosk 21" data-name="Kiosk 21" id="myCheckBox30" onchange="checkDisabled(testing);"/> Kiosk 21 </label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Sepang" data-name="Sepang" id="myCheckBox31" onchange="checkDisabled(testing);"/> Sepang</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="22" data-id="Kiosk 22" data-name="Kiosk 22" id="myCheckBox32" onchange="checkDisabled(testing);"/> Kiosk 22 </label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Kajang" data-name="Kajang" id="myCheckBox33" onchange="checkDisabled(testing);"/> Kajang</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="23" data-id="Kiosk 23" data-name="Kiosk 23" id="myCheckBox34" onchange="checkDisabled(testing);"/> Kiosk 23 </label></li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label><input type="checkbox" data-id="Putrajaya" data-name="Putrajaya" id="myCheckBox35" onchange="checkDisabled(testing);"/> Putrajaya</label>
<ul id="navlist">
<li><label><input type="checkbox" name="kioskMaster[]" value="24" data-id="Kiosk 24" data-name="Kiosk 24" id="myCheckBox36" onchange="checkDisabled(testing);"/> Kiosk 24</label></li>
</ul>
</li>
<hr/>
<li>
<label><input type="checkbox" data-id="Kuala Lumpur" data-name="Kuala Lumpur" id="myCheckBox37" onchange="checkDisabled(testing);"/> Kuala Lumpur</label>
<ul id="navlist">
<li><label><input type="checkbox" data-id="Kepong" data-name="Kepong" id="myCheckBox38" onchange="checkDisabled(testing);"/> Kepong</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="26" data-id="Kiosk 26" data-name="Kiosk 26" id="myCheckBox39" onchange="checkDisabled(testing);"/> Kiosk 26</label></li>
<li><label><input type="checkbox" name="kioskMaster[]" value="27" data-id="Kiosk 27" data-name="Kiosk 27" id="myCheckBox40" onchange="checkDisabled(testing);"/> Kiosk 27</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Taman Melawati" data-name="Taman Melawati" id="myCheckBox41" onchange="checkDisabled(testing);"/> Taman Melawati</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="28" data-id="Kiosk 28" data-name="Kiosk 28" id="myCheckBox42" onchange="checkDisabled(testing);"/> Kiosk 28</label></li>
<li><label><input type="checkbox" name="kioskMaster[]" value="29" data-id="Kiosk 29" data-name="Kiosk 29" id="myCheckBox43" onchange="checkDisabled(testing);"/> Kiosk 29</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="UTC Pudu" data-name="UTC Pudu" id="myCheckBox44" onchange="checkDisabled(testing);"/> UTC Pudu</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="30" data-id="Kiosk 30" data-name="Kiosk 30" id="myCheckBox45" onchange="checkDisabled(testing);"/> Kiosk 30</label></li>
<li><label><input type="checkbox" name="kioskMaster[]" value="31" data-id="Kiosk 31" data-name="Kiosk 31" id="myCheckBox46" onchange="checkDisabled(testing);"/> Kiosk 31</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Dua Sentral" data-name="Dua Sentral" id="myCheckBox47" onchange="checkDisabled(testing);"/> Dua Sentral</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="32" data-id="Kiosk 32" data-name="Kiosk 32" id="myCheckBox48" onchange="checkDisabled(testing);"/> Kiosk 32</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Jalan Klang Lama" data-name="Jalan Klang Lama" id="myCheckBox49" onchange="checkDisabled(testing);"/> Jalan Klang Lama</label>
<ul>
<li><label><input type="checkbox" name="kioskMaster[]" value="33" data-id="Kiosk 33" data-name="Kiosk 33" id="myCheckBox50" onchange="checkDisabled(testing);"/> Kiosk 33</label></li>
<li><label><input type="checkbox" name="kioskMaster[]" value="34" data-id="Kiosk 34" data-name="Kiosk 34" id="myCheckBox51" onchange="checkDisabled(testing);"/> Kiosk 34</label></li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label><input type="checkbox" data-id="Pahang" data-name="Pahang" id="myCheckBox52" onchange="checkDisabled(testing);"/> Pahang</label>
<ul id="navlist">
<li><label><input type="checkbox" data-id="Kuantan" data-name="Kuantan" id="myCheckBox53" onchange="checkDisabled(testing);"/> Kuantan</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="35" data-id="Kiosk 35" data-name="Kiosk 35" id="myCheckBox54" onchange="checkDisabled(testing);"/> Kiosk 35</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="UTC Kuantan" data-name="UTC Kuantan" id="myCheckBox55" onchange="checkDisabled(testing);"/> UTC Kuantan</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="36" data-id="Kiosk 36" data-name="Kiosk 36" id="myCheckBox56" onchange="checkDisabled(testing);"/> Kiosk 36</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Temerloh" data-name="Temerloh" id="myCheckBox57" onchange="checkDisabled(testing);"/> Temerloh</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="37" data-id="Kiosk 37" data-name="Kiosk 37" id="myCheckBox58" onchange="checkDisabled(testing);"/> Kiosk 37</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Bentong" data-name="Bentong" id="myCheckBox59" onchange="checkDisabled(testing);"/> Bentong</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="6" data-id="Kiosk 6" data-name="Kiosk 6" id="myCheckBox60" onchange="checkDisabled(testing);"/> Kiosk 6</label></li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label><input type="checkbox" data-id="Perak" data-name="Perak" id="myCheckBox61" onchange="checkDisabled(testing);"/> Perak</label>
<ul id="navlist">
<li><label><input type="checkbox" data-id="Ipoh" data-name="Ipoh" id="myCheckBox62" onchange="checkDisabled(testing);"/> Ipoh</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="38" data-id="Kiosk 38" data-name="Kiosk 38" id="myCheckBox63" onchange="checkDisabled(testing);"/> Kiosk 38</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="UTC Ipoh" data-name="UTC Ipoh" id="myCheckBox64" onchange="checkDisabled(testing);"/> UTC Ipoh</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="39" data-id="Kiosk 39" data-name="Kiosk 39" id="myCheckBox65" onchange="checkDisabled(testing);"/> Kiosk 39</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Taiping" data-name="Taiping" id="myCheckBox66" onchange="checkDisabled(testing);"/> Taiping</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="40" data-id="Kiosk 40" data-name="Kiosk 40" id="myCheckBox67" onchange="checkDisabled(testing);"/> Kiosk 40</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Teluk Intan" data-name="Teluk Intan" id="myCheckBox68" onchange="checkDisabled(testing);"/> Teluk Intan</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="41" data-id="Kiosk 41" data-name="Kiosk 41" id="myCheckBox69" onchange="checkDisabled(testing);"/> Kiosk 41</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Sri Manjung" data-name="Sri Manjung" id="myCheckBox70" onchange="checkDisabled(testing);"/> Sri Manjung</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="42" data-id="Kiosk 42" data-name="Kiosk 42" id="myCheckBox71" onchange="checkDisabled(testing);"/> Kiosk 42</label></li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label><input type="checkbox" data-id="Kedah" data-name="Kedah" id="myCheckBox72" onchange="checkDisabled(testing);"/> Kedah</label>
<ul id="navlist">
<li><label><input type="checkbox" data-id="Alor Setar" data-name="Alor Setar" id="myCheckBox73" onchange="checkDisabled(testing);"/> Alor Setar</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="43" data-id="Kiosk 43" data-name="Kiosk 43" id="myCheckBox74" onchange="checkDisabled(testing);"/> Kiosk 43</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="UTC Alor Setar" data-name="UTC Alor Setar" id="myCheckBox75" onchange="checkDisabled(testing);"/> UTC Alor Setar</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="44" data-id="Kiosk 44" data-name="Kiosk 44" id="myCheckBox76" onchange="checkDisabled(testing);"/> Kiosk 44</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Sungai Petani" data-name="Sungai Petani" id="myCheckBox77" onchange="checkDisabled(testing);"/> Sungai Petani</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="45" data-id="Kiosk 45" data-name="Kiosk 45" id="myCheckBox78" onchange="checkDisabled(testing);"/> Kiosk 45</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Kulim" data-name="Kulim" id="myCheckBox79" onchange="checkDisabled(testing);"/> Kulim</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="46" data-id="Kiosk 46" data-name="Kiosk 46" id="myCheckBox80" onchange="checkDisabled(testing);"/> Kiosk 46</label></li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label><input type="checkbox" data-id="Pulau Pinang" data-name="Pulau Pinang" id="myCheckBox81" onchange="checkDisabled(testing);"/> Pulau Pinang</label>
<ul id="navlist">
<li><label><input type="checkbox" data-id="Seberang Jaya" data-name="Seberang Jaya" id="myCheckBox82" onchange="checkDisabled(testing);"/> Seberang Jaya</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="47" data-id="Kiosk 47" data-name="Kiosk 47" id="myCheckBox83" onchange="checkDisabled(testing);"/> Kiosk 47</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Pulau Pinang" data-name="Pulau Pinang" id="myCheckBox84" onchange="checkDisabled(testing);"/> Pulau Pinang</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="48" data-id="Kiosk 48" data-name="Kiosk 48" id="myCheckBox85" onchange="checkDisabled(testing);"/> Kiosk 48</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Nibong Tebal" data-name="Nibong Tebal" id="myCheckBox86" onchange="checkDisabled(testing);"/> Nibong Tebal</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="49" data-id="Kiosk 49" data-name="Kiosk 49" id="myCheckBox87" onchange="checkDisabled(testing);"/> Kiosk 49</label></li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label><input type="checkbox" data-id="Melaka" data-name="Melaka" id="myCheckBox88" onchange="checkDisabled(testing);"/> Melaka</label>
<ul id="navlist">
<li><label><input type="checkbox" data-id="Bandar Melaka" data-name="Bandar Melaka" id="myCheckBox89" onchange="checkDisabled(testing);"/> Bandar Melaka</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="50" data-id="Kiosk 50" data-name="Kiosk 50" id="myCheckBox90" onchange="checkDisabled(testing);"/> Kiosk 50</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="UTC Melaka" data-name="UTC Melaka" id="myCheckBox91" onchange="checkDisabled(testing);"/> UTC Melaka</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="51" data-id="Kiosk 51" data-name="Kiosk 51" id="myCheckBox92" onchange="checkDisabled(testing);"/> Kiosk 51</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="TNB Jasin" data-name="TNB Jasin" id="myCheckBox93" onchange="checkDisabled(testing);"/> TNB Jasin</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="25" data-id="Kiosk 25" data-name="Kiosk 25" id="myCheckBox94" onchange="checkDisabled(testing);"/> Kiosk 25</label></li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label><input type="checkbox" data-id="Perlis" data-name="Perlis" id="myCheckBox95" onchange="checkDisabled(testing);"/> Perlis</label>
<ul id="navlist">
<li><label><input type="checkbox" name="kioskMaster[]" value="52" data-id="Kiosk 52" data-name="Kiosk 52" id="myCheckBox96" onchange="checkDisabled(testing);"/> Kiosk 52</label></li>
</ul>
</li>
<hr/>
<li>
<label><input type="checkbox" data-id="Negeri Sembilan" data-name="Negeri Sembilan" id="myCheckBox97" onchange="checkDisabled(testing);"/> Negeri Sembilan</label>
<ul id="navlist">
<li><label><input type="checkbox" data-id="Seremban" data-name="Seremban" id="myCheckBox98" onchange="checkDisabled(testing);"/> Seremban</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="53" data-id="Kiosk 53" data-name="Kiosk 53" id="myCheckBox99" onchange="checkDisabled(testing);"/> Kiosk 53</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Nilai" data-name="Nilai" id="myCheckBox100" onchange="checkDisabled(testing);"/> Nilai</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="54" data-id="Kiosk 54" data-name="Kiosk 54" id="myCheckBox101" onchange="checkDisabled(testing);"/> Kiosk 54</label></li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label><input type="checkbox" data-id="Kelantan" data-name="Kelantan" id="myCheckBox122" onchange="checkDisabled(testing);"/> Kelantan</label>
<ul id="navlist">
<li><label><input type="checkbox" name="kioskMaster[]" value="62" data-id="Kiosk 62" data-name="Kiosk 62" id="myCheckBox123" onchange="checkDisabled(testing);"/> Kiosk 62</label></li>
</ul>
</li>
<hr/>
<li>
<label><input type="checkbox" data-id="Terengganu" data-name="Terengganu" id="myCheckBox124" onchange="checkDisabled(testing);"/> Terengganu</label>
<ul id="navlist">
<li><label><input type="checkbox" data-id="Terengganu" data-name="Terengganu" id="myCheckBox125" onchange="checkDisabled(testing);"/> Terengganu</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="63" data-id="Kiosk 63" data-name="Kiosk 63" id="myCheckBox126" onchange="checkDisabled(testing);"/> Kiosk 63</label></li>
</ul>
</li>
<li><label><input type="checkbox" data-id="Kemaman" data-name="Kemaman" id="myCheckBox127" onchange="checkDisabled(testing);"/> Kemaman</label>
<ul >
<li><label><input type="checkbox" name="kioskMaster[]" value="64" data-id="Kiosk 64" data-name="Kiosk 64" id="myCheckBox128" onchange="checkDisabled(testing);"/> Kiosk 64</label></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div>
<p>Selected items (readable): <span class="selected-readable" id="selected-readable"></span></p>
<p>Selected items: <span class="selected">[]</span></p>
<p>Excepted items: <span class="excepted">[]</span></p>
</div>
<div class="checkbox">
<input type="hidden" name="modeType" value="0">
<button id="testing" type="submit" class="btn btn-primary" onclick="return submitForm()" disabled>Submit </button>
</div>
<div id="myResponse"></div>
这是我的JavaScript - 我尝试使用提交,禁用&amp;启用功能:
<script type='text/javascript'>
function checkDisabled(yourSubmitButton) {
for (var i = 0; i <= 128; i++) {
if (document.getElementById("myCheckBox" + i).checked == true) {
yourSubmitButton.disabled = false;
}
}
for (var i = 0; i <= 128; i++) {
if (document.getElementById("myICheckBox" + i).checked == true) {
yourSubmitButton.disabled = false;
}
}
};
我尝试了几种方法,但它有一些问题。它是一个嵌套的复选框,我还是JavaScript的新手,所以我不确定我是否正确地使用它。由于Stackoverflow中字数的限制,我删除了一些重复的复选框代码。
答案 0 :(得分:3)
您可以使用类似
的内容
function checkDisabled(yourSubmitButton) {
yourSubmitButton.disabled = true;
var els = document.querySelectorAll('input[type="checkbox"]');
for (var i = 0; i < els.length; i++) {
if (els[i].checked == true) {
yourSubmitButton.disabled = false;
break;
}
}
};
<form action="" id="myform" name="myform" class="myform">
<div class="anchor">
<ul>
<li>
<label>
<input type="checkbox" data-id="All Master" data-name="All Master" id="myCheckBox0" onchange="checkDisabled(testing);" />All Kedai Kiosk On Master Mode</label>
<ul>
<li>
<label>
<input type="checkbox" data-id="Selangor" data-name="Selangor" id="myCheckBox1" onchange="checkDisabled(testing);" />Selangor</label>
<ul id="navlist">
<li>
<label>
<input type="checkbox" data-id="Petaling Jaya" data-name="Petaling Jaya" id="myCheckBox2" onchange="checkDisabled(testing);" />Petaling Jaya </label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="1" data-id="Kiosk 1" data-name="Kiosk 1" id="myCheckBox3" onchange="checkDisabled(testing);" />Kiosk 1 </label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Puchong" data-name="Puchong" id="myCheckBox4" onchange="checkDisabled(testing);" />Puchong </label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="2" data-id="Kiosk 2" data-name="Kiosk 2" id="myCheckBox5" onchange="checkDisabled(testing);" /> Kiosk 2 </label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Subang Hub" data-name="Subang Hub" id="myCheckBox6" onchange="checkDisabled(testing);" /> Subang Hub </label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="5" data-id="Kiosk 5" data-name="Kiosk 5" id="myCheckBox7" onchange="checkDisabled(testing);" /> Kiosk 5 </label>
</li>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="20" data-id="Kiosk 20" data-name="Kiosk 20" id="myCheckBox8" onchange="checkDisabled(testing);" /> Kiosk 20 </label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Shah Alam" data-name="Shah Alam" id="myCheckBox12" onchange="checkDisabled(testing);" /> Shah Alam </label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="9" data-id="Kiosk 9" data-name="Kiosk 9" id="myCheckBox13" onchange="checkDisabled(testing);" /> Kiosk 9 </label>
</li>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="10" data-id="Kiosk 10" data-name="Kiosk 10" id="myCheckBox14" onchange="checkDisabled(testing);" /> Kiosk 10 </label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Cheras" data-name="Cheras" id="myCheckBox15" onchange="checkDisabled(testing);" /> Cheras </label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="11" data-id="Kiosk 11" data-name="Kiosk 11" id="myCheckBox16" onchange="checkDisabled(testing);" /> Kiosk 11 </label>
</li>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="12" data-id="Kiosk 12" data-name="Kiosk 12" id="myCheckBox17" onchange="checkDisabled(testing);" /> Kiosk 12 </label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Pelabuhan Klang" data-name="Pelabuhan Klang" id="myCheckBox24" onchange="checkDisabled(testing);" />Pelabuhan Klang</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="17" data-id="Kiosk 17" data-name="Kiosk 17" id="myCheckBox25" onchange="checkDisabled(testing);" /> Kiosk 17 </label>
</li>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="18" data-id="Kiosk 18" data-name="Kiosk 18" id="myCheckBox26" onchange="checkDisabled(testing);" /> Kiosk 18 </label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Kuala Selangor" data-name="Kuala Selangor" id="myCheckBox29" onchange="checkDisabled(testing);" />Kuala Selangor</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="21" data-id="Kiosk 21" data-name="Kiosk 21" id="myCheckBox30" onchange="checkDisabled(testing);" /> Kiosk 21 </label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Sepang" data-name="Sepang" id="myCheckBox31" onchange="checkDisabled(testing);" />Sepang</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="22" data-id="Kiosk 22" data-name="Kiosk 22" id="myCheckBox32" onchange="checkDisabled(testing);" /> Kiosk 22 </label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Kajang" data-name="Kajang" id="myCheckBox33" onchange="checkDisabled(testing);" />Kajang</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="23" data-id="Kiosk 23" data-name="Kiosk 23" id="myCheckBox34" onchange="checkDisabled(testing);" /> Kiosk 23 </label>
</li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label>
<input type="checkbox" data-id="Putrajaya" data-name="Putrajaya" id="myCheckBox35" onchange="checkDisabled(testing);" />Putrajaya</label>
<ul id="navlist">
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="24" data-id="Kiosk 24" data-name="Kiosk 24" id="myCheckBox36" onchange="checkDisabled(testing);" />Kiosk 24</label>
</li>
</ul>
</li>
<hr/>
<li>
<label>
<input type="checkbox" data-id="Kuala Lumpur" data-name="Kuala Lumpur" id="myCheckBox37" onchange="checkDisabled(testing);" />Kuala Lumpur</label>
<ul id="navlist">
<li>
<label>
<input type="checkbox" data-id="Kepong" data-name="Kepong" id="myCheckBox38" onchange="checkDisabled(testing);" />Kepong</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="26" data-id="Kiosk 26" data-name="Kiosk 26" id="myCheckBox39" onchange="checkDisabled(testing);" />Kiosk 26</label>
</li>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="27" data-id="Kiosk 27" data-name="Kiosk 27" id="myCheckBox40" onchange="checkDisabled(testing);" />Kiosk 27</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Taman Melawati" data-name="Taman Melawati" id="myCheckBox41" onchange="checkDisabled(testing);" />Taman Melawati</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="28" data-id="Kiosk 28" data-name="Kiosk 28" id="myCheckBox42" onchange="checkDisabled(testing);" />Kiosk 28</label>
</li>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="29" data-id="Kiosk 29" data-name="Kiosk 29" id="myCheckBox43" onchange="checkDisabled(testing);" />Kiosk 29</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="UTC Pudu" data-name="UTC Pudu" id="myCheckBox44" onchange="checkDisabled(testing);" />UTC Pudu</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="30" data-id="Kiosk 30" data-name="Kiosk 30" id="myCheckBox45" onchange="checkDisabled(testing);" />Kiosk 30</label>
</li>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="31" data-id="Kiosk 31" data-name="Kiosk 31" id="myCheckBox46" onchange="checkDisabled(testing);" />Kiosk 31</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Dua Sentral" data-name="Dua Sentral" id="myCheckBox47" onchange="checkDisabled(testing);" />Dua Sentral</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="32" data-id="Kiosk 32" data-name="Kiosk 32" id="myCheckBox48" onchange="checkDisabled(testing);" />Kiosk 32</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Jalan Klang Lama" data-name="Jalan Klang Lama" id="myCheckBox49" onchange="checkDisabled(testing);" />Jalan Klang Lama</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="33" data-id="Kiosk 33" data-name="Kiosk 33" id="myCheckBox50" onchange="checkDisabled(testing);" />Kiosk 33</label>
</li>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="34" data-id="Kiosk 34" data-name="Kiosk 34" id="myCheckBox51" onchange="checkDisabled(testing);" />Kiosk 34</label>
</li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label>
<input type="checkbox" data-id="Pahang" data-name="Pahang" id="myCheckBox52" onchange="checkDisabled(testing);" />Pahang</label>
<ul id="navlist">
<li>
<label>
<input type="checkbox" data-id="Kuantan" data-name="Kuantan" id="myCheckBox53" onchange="checkDisabled(testing);" />Kuantan</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="35" data-id="Kiosk 35" data-name="Kiosk 35" id="myCheckBox54" onchange="checkDisabled(testing);" />Kiosk 35</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="UTC Kuantan" data-name="UTC Kuantan" id="myCheckBox55" onchange="checkDisabled(testing);" />UTC Kuantan</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="36" data-id="Kiosk 36" data-name="Kiosk 36" id="myCheckBox56" onchange="checkDisabled(testing);" />Kiosk 36</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Temerloh" data-name="Temerloh" id="myCheckBox57" onchange="checkDisabled(testing);" />Temerloh</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="37" data-id="Kiosk 37" data-name="Kiosk 37" id="myCheckBox58" onchange="checkDisabled(testing);" />Kiosk 37</label>
</li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label>
<input type="checkbox" data-id="Perak" data-name="Perak" id="myCheckBox61" onchange="checkDisabled(testing);" />Perak</label>
<ul id="navlist">
<li>
<label>
<input type="checkbox" data-id="Ipoh" data-name="Ipoh" id="myCheckBox62" onchange="checkDisabled(testing);" />Ipoh</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="38" data-id="Kiosk 38" data-name="Kiosk 38" id="myCheckBox63" onchange="checkDisabled(testing);" />Kiosk 38</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="UTC Ipoh" data-name="UTC Ipoh" id="myCheckBox64" onchange="checkDisabled(testing);" />UTC Ipoh</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="39" data-id="Kiosk 39" data-name="Kiosk 39" id="myCheckBox65" onchange="checkDisabled(testing);" />Kiosk 39</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Taiping" data-name="Taiping" id="myCheckBox66" onchange="checkDisabled(testing);" />Taiping</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="40" data-id="Kiosk 40" data-name="Kiosk 40" id="myCheckBox67" onchange="checkDisabled(testing);" />Kiosk 40</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Teluk Intan" data-name="Teluk Intan" id="myCheckBox68" onchange="checkDisabled(testing);" />Teluk Intan</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="41" data-id="Kiosk 41" data-name="Kiosk 41" id="myCheckBox69" onchange="checkDisabled(testing);" />Kiosk 41</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Sri Manjung" data-name="Sri Manjung" id="myCheckBox70" onchange="checkDisabled(testing);" />Sri Manjung</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="42" data-id="Kiosk 42" data-name="Kiosk 42" id="myCheckBox71" onchange="checkDisabled(testing);" />Kiosk 42</label>
</li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label>
<input type="checkbox" data-id="Kedah" data-name="Kedah" id="myCheckBox72" onchange="checkDisabled(testing);" />Kedah</label>
<ul id="navlist">
<li>
<label>
<input type="checkbox" data-id="Alor Setar" data-name="Alor Setar" id="myCheckBox73" onchange="checkDisabled(testing);" />Alor Setar</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="43" data-id="Kiosk 43" data-name="Kiosk 43" id="myCheckBox74" onchange="checkDisabled(testing);" />Kiosk 43</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="UTC Alor Setar" data-name="UTC Alor Setar" id="myCheckBox75" onchange="checkDisabled(testing);" />UTC Alor Setar</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="44" data-id="Kiosk 44" data-name="Kiosk 44" id="myCheckBox76" onchange="checkDisabled(testing);" />Kiosk 44</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Sungai Petani" data-name="Sungai Petani" id="myCheckBox77" onchange="checkDisabled(testing);" />Sungai Petani</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="45" data-id="Kiosk 45" data-name="Kiosk 45" id="myCheckBox78" onchange="checkDisabled(testing);" />Kiosk 45</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Kulim" data-name="Kulim" id="myCheckBox79" onchange="checkDisabled(testing);" />Kulim</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="46" data-id="Kiosk 46" data-name="Kiosk 46" id="myCheckBox80" onchange="checkDisabled(testing);" />Kiosk 46</label>
</li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label>
<input type="checkbox" data-id="Pulau Pinang" data-name="Pulau Pinang" id="myCheckBox81" onchange="checkDisabled(testing);" />Pulau Pinang</label>
<ul id="navlist">
<li>
<label>
<input type="checkbox" data-id="Seberang Jaya" data-name="Seberang Jaya" id="myCheckBox82" onchange="checkDisabled(testing);" />Seberang Jaya</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="47" data-id="Kiosk 47" data-name="Kiosk 47" id="myCheckBox83" onchange="checkDisabled(testing);" />Kiosk 47</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Pulau Pinang" data-name="Pulau Pinang" id="myCheckBox84" onchange="checkDisabled(testing);" />Pulau Pinang</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="48" data-id="Kiosk 48" data-name="Kiosk 48" id="myCheckBox85" onchange="checkDisabled(testing);" />Kiosk 48</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Nibong Tebal" data-name="Nibong Tebal" id="myCheckBox86" onchange="checkDisabled(testing);" />Nibong Tebal</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="49" data-id="Kiosk 49" data-name="Kiosk 49" id="myCheckBox87" onchange="checkDisabled(testing);" />Kiosk 49</label>
</li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label>
<input type="checkbox" data-id="Melaka" data-name="Melaka" id="myCheckBox88" onchange="checkDisabled(testing);" />Melaka</label>
<ul id="navlist">
<li>
<label>
<input type="checkbox" data-id="Bandar Melaka" data-name="Bandar Melaka" id="myCheckBox89" onchange="checkDisabled(testing);" />Bandar Melaka</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="50" data-id="Kiosk 50" data-name="Kiosk 50" id="myCheckBox90" onchange="checkDisabled(testing);" />Kiosk 50</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="UTC Melaka" data-name="UTC Melaka" id="myCheckBox91" onchange="checkDisabled(testing);" />UTC Melaka</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="51" data-id="Kiosk 51" data-name="Kiosk 51" id="myCheckBox92" onchange="checkDisabled(testing);" />Kiosk 51</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="TNB Jasin" data-name="TNB Jasin" id="myCheckBox93" onchange="checkDisabled(testing);" />TNB Jasin</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="25" data-id="Kiosk 25" data-name="Kiosk 25" id="myCheckBox94" onchange="checkDisabled(testing);" />Kiosk 25</label>
</li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label>
<input type="checkbox" data-id="Perlis" data-name="Perlis" id="myCheckBox95" onchange="checkDisabled(testing);" />Perlis</label>
<ul id="navlist">
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="52" data-id="Kiosk 52" data-name="Kiosk 52" id="myCheckBox96" onchange="checkDisabled(testing);" />Kiosk 52</label>
</li>
</ul>
</li>
<hr/>
<li>
<label>
<input type="checkbox" data-id="Negeri Sembilan" data-name="Negeri Sembilan" id="myCheckBox97" onchange="checkDisabled(testing);" />Negeri Sembilan</label>
<ul id="navlist">
<li>
<label>
<input type="checkbox" data-id="Seremban" data-name="Seremban" id="myCheckBox98" onchange="checkDisabled(testing);" />Seremban</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="53" data-id="Kiosk 53" data-name="Kiosk 53" id="myCheckBox99" onchange="checkDisabled(testing);" />Kiosk 53</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Nilai" data-name="Nilai" id="myCheckBox100" onchange="checkDisabled(testing);" />Nilai</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="54" data-id="Kiosk 54" data-name="Kiosk 54" id="myCheckBox101" onchange="checkDisabled(testing);" />Kiosk 54</label>
</li>
</ul>
</li>
</ul>
</li>
<hr/>
<li>
<label>
<input type="checkbox" data-id="Kelantan" data-name="Kelantan" id="myCheckBox122" onchange="checkDisabled(testing);" />Kelantan</label>
<ul id="navlist">
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="62" data-id="Kiosk 62" data-name="Kiosk 62" id="myCheckBox123" onchange="checkDisabled(testing);" />Kiosk 62</label>
</li>
</ul>
</li>
<hr/>
<li>
<label>
<input type="checkbox" data-id="Terengganu" data-name="Terengganu" id="myCheckBox124" onchange="checkDisabled(testing);" />Terengganu</label>
<ul id="navlist">
<li>
<label>
<input type="checkbox" data-id="Terengganu" data-name="Terengganu" id="myCheckBox125" onchange="checkDisabled(testing);" />Terengganu</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="63" data-id="Kiosk 63" data-name="Kiosk 63" id="myCheckBox126" onchange="checkDisabled(testing);" />Kiosk 63</label>
</li>
</ul>
</li>
<li>
<label>
<input type="checkbox" data-id="Kemaman" data-name="Kemaman" id="myCheckBox127" onchange="checkDisabled(testing);" />Kemaman</label>
<ul>
<li>
<label>
<input type="checkbox" name="kioskMaster[]" value="64" data-id="Kiosk 64" data-name="Kiosk 64" id="myCheckBox128" onchange="checkDisabled(testing);" />Kiosk 64</label>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
<div>
<p>Selected items (readable): <span class="selected-readable" id="selected-readable"></span>
</p>
<p>Selected items: <span class="selected">[]</span>
</p>
<p>Excepted items: <span class="excepted">[]</span>
</p>
</div>
<div class="checkbox">
<input type="hidden" name="modeType" value="0">
<button id="testing" type="submit" class="btn btn-primary" onclick="return submitForm()" disabled>Submit</button>
</div>
<div id="myResponse"></div>
</form>