不要在标签点击事件上切换标签

时间:2017-05-02 09:24:23

标签: javascript jquery jquery-ui tabs

我希望每当用户点击tab时调用一个函数,如果该函数返回false,我想留在同一个标​​签上,否则移动到用户按下的标签。

我在tab开关上绑定一个事件。

rpmbuild -bb rpm.spec

但是当我这样做时,问题是,因为这个$(".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 );事件,还有其他方法保留在早期标签或如何避免这种情况?

1 个答案:

答案 0 :(得分:0)

$('.selector').on('click',function(){
    if (flag == false) {
        $(this).removeClass('active in') ;                 
        return false;
    }
})
相关问题