[英]How can I find out which radio button is selected using jQuery without searching for the radio group each time?
I know I can use something described here: How can I know which radio button is selected via jQuery? 我知道我可以使用这里描述的内容: 我怎么知道通过jQuery选择了哪个单选按钮?
ie jQuery("input[name=myradiogroup]:checked").val()
to get the selected radio button value. 即jQuery("input[name=myradiogroup]:checked").val()
获取所选的单选按钮值。 But I'd like to cache the radio group and determine which value is selected at a later point in time. 但我想缓存无线电组并确定在以后的某个时间点选择了哪个值。
I want to do something like: 我想做的事情如下:
var myRadio = jQuery("input[name=myradiogroup]");
//some code
var value = myRadio.getCheckedButton().val();
Any way to do this or do I have to explicitly run the selector with :checked
in it every time I want to find out the selected value? 任何方式这样做或我必须显式运行选择器:checked
每次我想找到所选值时:checked
入它?
var myRadio = jQuery("input[name=myradiogroup]");
var selectedRadio = myRadio.filter(":checked");
alert( selectedRadio.val() );
能做
myRadio.filter(':checked').val()
myValue="";
$('input[name=myradiogroup]').change(function() {
myValue= this.value;
alert(myValue);
});
Now you can check "myValue" anytime you wish. 现在您可以随时查看“myValue”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.