[點(diǎn)晴永久免費(fèi)OA]【JavaScript】jQuery遍歷checked元素控件列表判斷是否全部選中并傳遞id值
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Document</title> <script type="text/javascript" src="jquery.js"></script> <style type="text/css"> .inputs{ width: 500px; height: 500px; border: 1px solid #333; background-color: #FF9800; margin: 2% auto; } .inputs input{ width: 30px; height: 30px; } .inputs input:after{ } .btn{ color: #fff; border: 1px solid #fff; margin: 5% auto; background-color: #ff9800; } </style> <script type="text/javascript"> $().ready(function() { var $giveID = $("#giveID"); $giveID.click(function(){ var storesID = []; var ids = document.getElementsByName("ids"); var flag = false ;//標(biāo)記判斷是否選中一個(gè) for(var i=0;i<ids.length;i++){ if(ids[i].checked){ flag = true; storesID.push(ids[i].value); //如果有id,可以把value改成id console.log(storesID); } } if(!flag){ alert("請(qǐng)最少選擇一項(xiàng)!"); return false ; } }) }); </script> </head> <body> <div> <input type="checkbox" name="ids" value="1"> <input type="checkbox" name="ids" value="2"> <input type="checkbox" name="ids" value="3"> <input type="checkbox" name="ids" value="4"> <input type="checkbox" name="ids" value="5"> <input type="checkbox" name="ids" value="6"> <input type="checkbox" name="ids" value="7"> <input type="checkbox" name="ids" value="8"> <input type="checkbox" name="ids" value="9"> <input type="checkbox" name="ids" value="10"> <input type="checkbox" name="ids" value="11"> <input type="checkbox" name="ids" value="12"> <button id="giveID">選中后點(diǎn)擊我</button> </div> </body> </html> 該文章在 2023/4/28 15:32:45 編輯過 |
關(guān)鍵字查詢
相關(guān)文章
正在查詢... |