简体   繁体   English

我使用php创建了一个动态复选框,但是当我使用.checked()进行检查时,仅选中了第一个单选按钮。 如何检查其余部分?

[英]I have created a dynamic checkbox using php, but when i use .checked() to check it, only first radio button is checked. how to check the rest?

<div  id="pop2" class="box2" style="display: none">
    <form action="" method="post">
        <div class="second" style="margin-top:3px;margin-left:10px;font-size:100%">Add to</div>
<?php 
    $new2=array();
    $new2=getlist();
    foreach($new2 as $value){ 
        echo'<input type="radio" id="qwerty" name="qwerty" value="'.$value.'" onclick="theLast()"  />';

        echo"$value";echo"<br>";}
?>
        <hr>
        <button type="button" id="add2" class="new" onclick="theFinal()" >Create new list</button>
  </form>
</div>

and i used javascript to check in theLast() function 我用JavaScript来检查theLast()函数

  if (document.getElementById('qwerty').checked) {
      window.lists=document.getElementById('qwerty').value;
  }

only first radio button is working fine, rest are not detected in .checked() 只有第一个单选按钮可以正常工作,.checked()中未检测到其余按钮

Having the same id attribute for all the checkboxes can cause these kinds of issues. 所有复选框具有相同的id属性可能会导致此类问题。 I would suggest using a commom class instead and iterating the checkboxes using the getElementByClassName function to check for "checked" boxes. 我建议改用commom类,并使用getElementByClassName函数迭代复选框以检查“已选中”复选框。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何检查单选或复选框? - How can I check if radio or checkbox is checked? 如何检查是否使用JavaScript检查了单选按钮? - How do I check if a radio button is checked using JavaScript? 如何将事件侦听器添加到动态创建的复选框,以及如何检查复选框是否已选中。 JavaScript的 - How to add event listener to a dynamically created checkbox and check if checkbox is checked. JavaScript 如何在没有提交按钮的情况下检查单选按钮是否被选中? - How can i check if the radio button is checked or not without a submit button? 我正在尝试选中父项时选中所有子项复选框。 但这只能工作一次! 下次尝试时,孩子不会受到检查? - I'm trying to check all child check boxes when parent is checked. But this works only once ! When i try it the next time, child doesn't gets checked? 如何检查单选按钮是否使用 JQuery 检查? - How to check radio button is checked using JQuery? 选中另一个复选框后,如何检查该复选框? [JavaScript的] - How can I check a checkbox when another checkbox is checked? [JavaScript] 如果未选中,如何检查单选名称按钮的数组 - How can I check the array of radio name button if it is not checked 如何检查是否选中了单选按钮? - How to check if a radio button is checked? 如何使用Javascript检查其他单选按钮中是否选中了特定的单选按钮? - How do i check if a specific Radio button is checked among the other radio buttons using Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM