gpt4 book ai didi

jquery - 如何设置单选按钮通过其文本值进行检查

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

我正在尝试根据单选按钮的文本值设置“选中”

这是我的 HTML 代码

<section class="trainers_listWrap">
<li><label class="mt-radio mt-radio-outline traine">
<input type="radio" data-value="One" class="trainerradio" value="62" name="trainernames">One
<span></span>
</label>
</li>
<li><label class="mt-radio mt-radio-outline traine">
<input type="radio" data-value="Two" class="trainerradio" value="9" name="trainernames">Two
<span></span>
</label>
</li>
<li><label class="mt-radio mt-radio-outline traine">
<input type="radio" data-value="THree" class="trainerradio" value="17" name="trainernames">THree
<span></span>
</label>
</li>

</section>

我尝试过(尝试检查上面 HTML 中的两个单选按钮)

 $('input:radio[name="trainernames"][value="Two"]').prop('checked', true);

这是我的 fiddle

http://jsfiddle.net/cod7ceho/376/

您能否告诉我如何根据单选按钮的文本值设置单选按钮

最佳答案

问题与您正在使用的 jQuery mobile 有关。要更改 radio 的状态(实际上,为了使此状态更改可见),在本例中,您还必须定位元素标签,并添加/删除适当的类:

$('input:radio[name="trainernames"][data-value="One"]').prev('label').addClass('ui-radio-on').removeClass('ui-radio-off');

演示:http://jsfiddle.net/cod7ceho/377/

附注也许可以找到更优雅的解决方案(在这种情况下不确定jquery移动的可能性)

编辑:

http://jsfiddle.net/cod7ceho/378/

$('input:radio[name="trainernames"][data-value="One"]').prop('checked',true);


$("input[type='radio']").checkboxradio("refresh");

基于此处的答案:Checking and unchecking radio buttons with Jquery Mobile

关于jquery - 如何设置单选按钮通过其文本值进行检查,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41159379/

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