jQuery:单选按钮名称包含字符串 [英] jQuery: radio button name contains string

查看:62
本文介绍了jQuery:单选按钮名称包含字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正试图定位一组单选按钮,这些单选按钮的名称包含字符串的一部分...

I'm trying to target a group of radio buttons that's name contains a part of a string...

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

那是行不通的...

推荐答案

jQuery包含选择器为~=

The jQuery Contains Selector is ~=

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

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

Also, $("input:radio[name=PercentageValue]:checked") will always be true, try using .is(":checked") which will return a boolean like so:

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

这篇关于jQuery:单选按钮名称包含字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆