检查其值= $编程的单选按钮

时间:2012-01-10 13:53:09

标签: jquery jquery-selectors radio-button

有一个单选按钮组定义如下:

<input type="radio" name="type0" value="$">$<input type="radio" name="type0" value="%">%

需要检查其值为$的第一个单选按钮。

问题是以下代码无法实现此目的。需要某种方法来转义$

$('input[type=radio][value=$]').attr('checked','checked');

4 个答案:

答案 0 :(得分:8)

$('input[type=radio][value="$"]').first().attr('checked','checked');

答案 1 :(得分:2)

这适用于我,将选择器用双引号括起来,将属性选择器用单个

括起来
$("input[type=radio][value='$']").attr('checked','checked');

http://jsfiddle.net/BuvKT/

答案 2 :(得分:2)

\\退出美元:

$('input[type=radio][value=\\$]:first').attr('checked','checked');

代码:http://jsfiddle.net/E6uBw/3/

答案 3 :(得分:0)

$('input[type="radio"][name="type0"][value="$"]:first').prop('checked', true);
相关问题