我有一个html表单内容,有两个复选框,如
<p class="text">
<input type="checkbox" value="Yes" id="ques11" name="radiobutton" class="option_1" />
<label for="ques11">True</label>
<span class="hide" id="ans1">Answer: True</span>
<span id="rite11" class="hide"><img class="imgsize" src="images/ans_correct.png"/></span>
<span id="wrong11" class="hide"><img class="imgsize" src="images/ans_wrong.png"/></span> </p>
<p class="text">
<input type="checkbox" value="No" id="ques12" name="radiobutton" class="option_2" />
<label for="ques12">False</label>
<span id="rite12" class="hide"><img class="imgsize" src="images/ans_correct.png"/></span>
<span id="wrong12" class="hide"><img class="imgsize" src="images/ans_wrong.png"/></span> </p>
为此我已经编写代码来获取复选框
$(function(){
$('#_submit').on('click', function(){
completedata = 'selected_';
$('input[type="checkbox"]').each(function(){
var quesNo = $(this).closest("div[id^='questionsNo_']").attr('id').split('_');
var chapterId = quesNo[1];
var questionId = quesNo[2];
var optionId = $(this).attr('class').split('_')[1];
var currentAns = $(this).val();
completedata += 'choose'+','+chapterId + ',' + questionId + ',' + optionId + ',' + currentAns + '_';
completedata = completedata.substr(0, completedata.length - 1) + '_selectedEnd';
if(completedata == "selected_selectedEnd"){
document.getElementById("selids").innerHTML="";
}
else {
$('#selids').text(completedata);
}
在这一行中,我必须选中哪个复选框,如何使用此脚本获取该复选框。请帮我怎么做。
var optionId = $(this).attr('class').split('_')[1];
我希望根据class =“option_1”或class =“option_2”点击哪个复选框。
答案 0 :(得分:1)
试试这个:
$("input[name='radiobutton']").click(function(){
if($(this).is(':checked'))
{
// checked
}
else
{
// unchecked
}
});