Disable bootstrap tab clicks

后端 未结 9 1179
走了就别回头了
走了就别回头了 2021-01-14 15:24

I am using bootsrap tabs for a registration form , I changed navigation of tabs using onclick event of next and previous button . But still that tabs click works and being

9条回答
  •  心在旅途
    2021-01-14 16:07

    I tried all suggested answers, but finally i made it work like this

    if (AnyCondition) //your condition
    {
        $("a[data-toggle='tab'").prop('disabled', true);
        $("a[data-toggle='tab'").each(function () {
            $(this).prop('data-href', $(this).attr('href')); // hold you original href
            $(this).attr('href', '#'); // clear href
        });                
        $("a[data-toggle='tab'").addClass('disabled-link');
    }
    else
    {
        $("a[data-toggle='tab'").prop('disabled', false);
        $("a[data-toggle='tab'").each(function () {
            $(this).attr('href', $(this).prop('data-href')); // restore original href
        });
        $("a[data-toggle='tab'").removeClass('disabled-link');
    }
    // if you want to show extra messages that the tab is disabled for a reason
    $("a[data-toggle='tab'").click(function(){
       alert('Tab is disabled for a reason');
    });
    

提交回复
热议问题