![](/img/trans.png)
[英]jquery mobile panel ONLY on the first page doesn't work after first time
[英]jquery mobile trigger click doesn't work the first time
我有一个带有几个无线电输入的jquery移动表格,选项“DS”,“NO”和“YES”。 我想当我点击一个按钮时,它会模拟所有单选按钮的“是”选项的点击。
我用这个代码:
$("#btn-all-yes").click(function(){
$(".replay-yes").each(function(index, element){
$(element).trigger("click");
//$(element).click();
});
});
但是我需要在按钮中单击两次以获得所需的结果。 如果我将行'$(element).trigger(“click”)'放两次就可以了,但我认为它应该只需单击一次click事件即可。
您可以在http://jsfiddle.net/qwLPH/7/看到所有代码
您需要使用.prop
更改其状态,然后刷新它.checkboxradio('refresh')
。
更新 - 取消选中其他按钮
$("#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");
});
});
尝试初始化页面加载上的点击:
$(".replay-yes").each(function (index, element) {
$(element).trigger("click");
//$(element).click();
}).click();
//-^^^^^^^----------this way
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.