[英]How to get the NAME and value of a radio button when DYNAMICALLY selected - in jQuery?
[英]Get ID of selected radio button in Jquery “name has []”
我正在使用在线产品,由于某种原因,当它生成有问题的页面时,单选按钮集的名称为product_id_page-0 [] <-“注意[]”
我想要做的是使用Jquery获取所选单选按钮的ID。 如果我用
var userType =$('#product_id_page-0[]:radio:checked').attr('id');
alert("xmlvalue is: " + userType);
什么都没发生
如果我用
var userType =$('#product_id_page-0:radio:checked').attr('id');
alert("xmlvalue is: " + userType);
我收到未定义的警报。
我无法更改单选按钮名称组,但是我认为方括号可能会破坏此处的内容。
请指教。
您需要使用两个斜杠对元字符进行转义:
var userType =$('#product_id_page-0\\[\\]:radio:checked').attr('id');
alert("xmlvalue is: " + userType);
如果这是名称而不是id,请使用:
var userType =$('[name=product_id_page-0\\[\\]]:radio:checked').attr('id');
alert("xmlvalue is: " + userType);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.