<div class="boxanswer"><input type="radio" name="idquestion[2]" value="2" class="checkradios"><span class='answer_choice'>A . 1</span></div>
<div class="boxanswer"><input type="radio" name="idquestion[2]" value="2" class="checkradios"><span class='answer_choice'>B. 2</span></div>
<div class="boxanswer"><input type="radio" name="idquestion[2]" value="3" class="checkradios"><span class='answer_choice'>C. 3</span></div>
<div class="boxanswer"><input type="radio" name="idquestion[2]" value="4" class="checkradios"><span class='answer_choice'>D. 4</span></div>
<div class="boxanswer"><input type="radio" name="idquestion[2]" value="5" class="checkradios"><span class='answer_choice'>E. 5</span></div>
这是我的javascript代码
$('input[type="radio"]').change(function(){
alert("You checked it");
});
每次我选中其中一个单选按钮时,我都会收到 6 个警告框,而不是 1 个警告。我的代码有什么问题?
最佳答案
我确定您是在一个循环中执行此操作的,该循环被迭代了 6 次。它在每个元素上绑定(bind)处理程序 6 次。只需从循环中删除您的代码,一切都会就绪。
someloop{
}
$('input[type="radio"]').change(function(){
alert("You checked it");
});
关于javascript - Jquery单选按钮重复,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36549647/