gpt4 book ai didi

jquery - 根据名称和值选择选择哪个单选按钮

转载 作者:行者123 更新时间:2023-12-01 02:33:03 25 4
gpt4 key购买 nike

我正在编写一个非常基本的显示/隐藏脚本,并基于检查下面两个单选按钮中的哪一个。我的问题是我无法将 id 添加到单选按钮,因为代码是动态生成的。有没有办法使用 JQuery 根据名称和值的组合来选择选中哪个框?一旦我有了 IF 语句,我就可以处理其余的事情,但我只知道如何使用类或 ID 来完成它。

<span class="wpcf7-form-control-wrap mysql">
<span id="mysql" class="wpcf7-form-control wpcf7-radio radiobuttons">
<span class="wpcf7-list-item">
<label>
<span class="wpcf7-list-item-label">Yes</span>
&nbsp;
<input type="radio" name="mysql" value="Yes">
</label>
</span>
<span class="wpcf7-list-item">
<label>
<span class="wpcf7-list-item-label">No</span>
&nbsp;
<input type="radio" name="mysql" value="No">
</label>
</span>
</span>
</span>

所以基本上我正在寻找类似“如果名称是mysql,值为是,并且选中单选按钮,则执行X。如果名称是mysql,则值为否,并且选中单选按钮,做Y。

提前致谢。

最佳答案

工作演示 http://jsfiddle.net/YLesK/3/

名称属性如果始终相同,所以我认为如果您检查 this.value ,您会没事的;否则,您可以添加此条件 $(this).prop('name') === "mysql" ==> http://jsfiddle.net/YLesK/5/

希望这有帮助,:)

代码

$(function(){
$('input[type="radio"]').click(function(){
if(this.value === "Yes")
alert("Do X I am yes");
else if (this.value === "No")
alert("Do Y I am No");
});

});

关于jquery - 根据名称和值选择选择哪个单选按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11320758/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com