[英]Do not switch tab on tab click event
我想在用戶單擊選項卡時調用一個函數,如果該函數返回false,我想保留在同一選項卡上,否則移至用戶按下的選項卡。
我在選項卡開關上綁定一個事件。
$(".selector").tabs();
$(".selector").bind("tabsactivate", function(event, ui) {
alert('oldTab = ' + ui.oldTab.index());
alert('newTab = ' + ui.newTab.index());
if (some_condition)
console.log("EQUAL");
else {
BootstrapDialog.confirm({
title: 'WARNING',
message: 'You have not saved the changes.Do you want to save it?.',
type: BootstrapDialog.TYPE_WARNING,
draggable: true,
callback: function(result) {
//if user presses ok, then i want to stay on the previous tab else move to the tab pressed
if (result) {
//stay on the same tab
$(".selector").tabs("option", "active", ui.oldTab.index());
} else
//moved to pressed tab
}
});
}
}
});
但是當我這樣做時,問題是,因為這個$( ".selector" ).tabs( "option", "active", index );
再次觸發此綁定事件。再次出現此確認對話框。 我不希望此bind
事件再次執行,是否還有其他方法可以保留在較早的選項卡上,或者如何避免這種情況?
$('.selector').on('click',function(){
if (flag == false) {
$(this).removeClass('active in') ;
return false;
}
})
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.