![](/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.