我想在用户单击选项卡时调用功能,如果该功能返回false,我想留在同一选项卡上,否则移动到用户按下的选项卡。<<<<<<<</p>
我在Tab Switch上绑定了一个事件。
$(".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;
}
})