我使用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>

和我使用javascript检查在theLast()函数

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

只有第一个单选按钮工作正常,其余的在。checked()中没有检测到

为所有复选框使用相同的id属性可能会导致这些问题。我建议使用一个通用类,并使用getElementByClassName函数迭代复选框,以检查"已选中"框。