【发布时间】:2020-09-03 11:37:17
【问题描述】:
试图提醒选中的单选按钮的 id。但它没有警报。
// Reference the form - see HTMLFormControlsCollection
var chxGrp = document.forms.checkGroup;
chxGrp.addEventListener('change', message);
/* The Event Object is passed through, you might've seen it as
|| "e" or "evt". How it's labelled doesn't matter because Event
|| Object is always available when you deal with the DOM.
*/
function message(event) {
// if the node clicked is a checkbox see if it's...
if (event.target.type === 'checkbox') {
// ... checked then...
if (event.target.checked) {
wrong_id = event.target.attr('id');
alert(wrong_id);
} else {}
}
return false;
}
<form id='checkGroup'>
Question 1
<div class="question_container">
<div class="question_div1">
<div class="question_div2">
<p>Some persons can do piece of work in 12 days. Twice the number of such persons will do half of that work in, how many days.</p>
<p> </p>
<input type="hidden" name="qid1" value="244">
<div class="option_div">
<input type="radio" name="radio1" id="checka1" value="A">
<label for="checka1">
<p>1</p>
</label>
</div>
<div class="option_div">
<input type="radio" name="radio1" id="checkb1" value="B">
<label for="checkb1">
<p>2</p>
</label>
</div>
<div class="option_div">
<input type="radio" name="radio1" id="checkc1" value="C">
<label for="checkc1">
<p>3</p>
</label>
</div>
<div class="option_div">
<input type="radio" name="radio1" id="checkd1" value="D">
<label for="checkd1">
<p>4</p>
</label>
</div>
<div class="option_div">
<input type="radio" name="radio1" id="checke1" value="E">
<label for="checke1">
<p>None of these</p>
</label>
</div>
</div>
</div>
</div>
Question 2
<div class="question_container">
<div class="question_div1">
<div class="question_div2">
<p>In a dairy farm, 40 cows eat 40 bags of husk in 40 days. In how many days one cow will eat one bag of husk.</p>
<input type="hidden" name="qid2" value="245">
<div class="option_div">
<input type="radio" name="radio2" id="checka2" value="A">
<label for="checka2">
<p> 44</p>
</label>
</div>
<div class="option_div">
<input type="radio" name="radio2" id="checkb2" value="B">
<label for="checkb2">
<p>45</p>
</label>
</div>
<div class="option_div">
<input type="radio" name="radio2" id="checkc2" value="C">
<label for="checkc2">
<p>48</p>
</label>
</div>
<div class="option_div">
<input type="radio" name="radio2" id="checkd2" value="D">
<label for="checkd2">
<p>40</p>
</label>
</div>
<div class="option_div">
<input type="radio" name="radio2" id="checke2" value="E">
<label for="checke2">
<p>None of these</p>
</label>
</div>
</div>
</div>
</div>
</form>
试图提醒选中的单选按钮的 id。但它没有警报。
试图提醒选中的单选按钮的 id。但它没有警报。
试图提醒选中的单选按钮的 id。但它没有警报。
【问题讨论】:
-
attr()是 jQuery 方法,不是原生 dom 元素方法
标签: javascript html jquery alert radio