jQuery:单选按钮名称包含字符串

时间:2011-01-12 18:01:53

标签: jquery

我正在尝试定位一组名称中包含字符串一部分的单选按钮...

if (!$("input:radio[name=PercentageValue]:checked"))
    alert("you need to check a percentage");

那不行......

2 个答案:

答案 0 :(得分:2)

jQuery Contains Selector是~=

http://api.jquery.com/attribute-contains-word-selector/

此外,$("input:radio[name=PercentageValue]:checked")始终为true,请尝试使用.is(":checked"),它将返回如下布尔值:

if (!$("input:radio[name=~'PercentageValue']").is(":checked"))
    alert("you need to check a percentage");

答案 1 :(得分:0)

尝试

if (!$("input:radio[name=PercentageValue]:checked").length)
    alert("you need to check a percentage");