Disable bootstrap tab clicks

后端 未结 9 1177
走了就别回头了
走了就别回头了 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:05
    $(document).ready(function(){
        $("#tabs > li").click(function(){
            if($(this).hasClass("disabled"))
                return false;
        });
    });
    

    It will be enough to work

    0 讨论(0)
  • 2021-01-14 16:06

    try this for disabling a tab

    $('#tab').attr('class', 'disabled');
    
        $('tab').click(function(event){
            if ($(this).hasClass('disabled')) {
                return false;
            }
        });
    
    0 讨论(0)
  • 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');
    });
    
    0 讨论(0)
提交回复
热议问题