获取选中的单选按钮的值,而无需重新选择按钮 [英] Get the value of checked radio button without re-selecting the buttons
本文介绍了获取选中的单选按钮的值,而无需重新选择按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我得到一些如下的按钮:
So I am getting some buttons as follows:
var reportFilterButtons = $('input[name=reportfilter]', '#reportChartForm');
此后,我可以轻松地按如下方式附加更改处理程序:
Later on this easily allows me to attach a change handler as follows:
reportFilterButtons.change(handlers.reportFilterButtonsChange);
在此处理程序内,我需要获取当前选中按钮的值,所以我这样做:
Inside of this handler I need to get the value of the currently checked button, so I do this:
var checkedReportFilterButton = $('input[name=reportfilter]:checked', '#reportChartForm');
....
if (checkedReportFilterButton.val() ....
reportFilterButtons
和checkedReportFilterButton
选择器似乎是多余的.有没有一种方法可以通过对reportFilterButtons
进行操作而不进行第二次选择来获取检查值/值?
The reportFilterButtons
and checkedReportFilterButton
selectors seem redundant however. Is there a way to get the checked/value by working against reportFilterButtons
and not doing the second selection?
推荐答案
您可以使用$.filter
查找已选中的内容:
You could use $.filter
to find the checked one:
reportFilterButtons.filter(':checked').val()
这篇关于获取选中的单选按钮的值,而无需重新选择按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文