获取先前检查的单选按钮 [英] Get previously checked Radio Button
问题描述
给出一组单选按钮,例如:
<input id="B_1" type="radio" name="radioName" value="1">
<input id="B_2" type="radio" name="radioName" value="2">
<input id="B_3" type="radio" name="radioName" value="3">
<input id="B_4" type="radio" name="radioName" value="4">
当
我尝试将以下函数附加到 我不知道是否有帮助,无论如何,这是完整的尝试: http://jsfiddle.net /H6h4R/ 尝试一下- http://jsfiddle. net/H6h4R/1/ Given a set of radio buttons, like: When one of them gets checked is it possible to know which was previously active (if there is one)? I tried to attach the following function to the I don't know if could be of any help, anyway here's the complete attempt: http://jsfiddle.net/H6h4R/ Try this - http://jsfiddle.net/H6h4R/1/ The 这篇关于获取先前检查的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!onclick
事件,但是它不起作用,因为它返回了当前选中的单选按钮,而不是之前选择的那个单选按钮:my_func = function() {
var checkedValue = $('input[type=radio]:checked').val();
return alert("The previously selected was: " + checkedValue);
};
$(":radio").on("mousedown", function() {
$("p").text( $('input[type=radio]:checked').val() );
}).on("mouseup", function() {
$('input[type=radio]').prop('checked', false);
$(this).prop('checked', true);
});
click
事件仅在以下一系列确切的事件之后触发:
<input id="B_1" type="radio" name="radioName" value="1">
<input id="B_2" type="radio" name="radioName" value="2">
<input id="B_3" type="radio" name="radioName" value="3">
<input id="B_4" type="radio" name="radioName" value="4">
onclick
event, but it doesn't work because it returns the the presently selected radio button instead of the one that was selected before:my_func = function() {
var checkedValue = $('input[type=radio]:checked').val();
return alert("The previously selected was: " + checkedValue);
};
$(":radio").on("mousedown", function() {
$("p").text( $('input[type=radio]:checked').val() );
}).on("mouseup", function() {
$('input[type=radio]').prop('checked', false);
$(this).prop('checked', true);
});
click
event is only triggered after this exact series of events: