gpt4 book ai didi

jquery-mobile - jquery mobile触发点击第一次不起作用

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

我有一个 jquery 移动表单,带有多个 radio 输入选项“DS”、“NO”和“YES”。我希望当我单击一个按钮时,它会模拟单击所有单选按钮的"is"选项。

我使用这个代码:

$("#btn-all-yes").click(function(){
$(".replay-yes").each(function(index, element){
$(element).trigger("click");
//$(element).click();
});
});

但我需要在按钮中单击两次才能达到所需的结果。如果我将行 '$(element).trigger("click")' 放置两次,它就可以工作,但我认为它应该通过对单击事件的一次调用来工作。

您可以在http://jsfiddle.net/qwLPH/7/查看所有代码

最佳答案

您需要使用 .prop 更改其状态,然后刷新它 .checkboxradio('refresh')

Working demo

更新 - 取消选中其他按钮

$("#btn-all-yes").click(function () {
$('[data-role="controlgroup"]').find("[type=radio]").each(function () {
if ($(this).hasClass('replay-yes')) {
$(this).prop('checked', true).checkboxradio("refresh");
} else {
$(this).prop('checked', false).checkboxradio("refresh");
}
});
});
<小时/>

旧答案

$("#btn-all-yes").click(function(){
$(".replay-yes").each(function(index, element){
$(element).prop('checked', true).checkboxradio("refresh");
});
});

关于jquery-mobile - jquery mobile触发点击第一次不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15806432/

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