jQuery 单选按钮新手问题
我有一个单选按钮表,其 ID 值包含项目编号
<input type="radio" id="rb169">
<input type="radio" id="rb170">
<input type="radio" id="rb171">
如何使用 jQuery 迭代所有以“rb”开头的单选按钮以确定选择了哪个 # 编号?
我有类似的东西:
return_type = $("input:radio["@name=rb*"]:checked").val();
if (return_type == undefined) {
alert("you did not select a radio button");
}
但这并不像我选择的那样工作。这是对的吗?
I have a table of radio buttons that have an ID value that contains an item number
<input type="radio" id="rb169">
<input type="radio" id="rb170">
<input type="radio" id="rb171">
How can I use jQuery to iterate through all the radio buttons that start with "rb" to determine which # number was selected?
I have something like:
return_type = $("input:radio["@name=rb*"]:checked").val();
if (return_type == undefined) {
alert("you did not select a radio button");
}
but this doesn't work the way I selected. Is this right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
$('input:radio[name^=rb]:checked').val()
应该这样做。您不再需要@
,也不再需要额外的引号。$('input:radio[name^=rb]:checked').val()
should do it. You don't need the@
anymore, nor the extra quotes.那应该有效。以 is ^=
开头 编辑:我注意到您的代码在其他地方也是错误的。我的视野太狭窄了。这是一个更新:
That should work. Starts with is ^=
EDIT: I noticed that your code is wrong in other places as well. I was too narrow in what I was looking at. Here is an update: