[英]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.