且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

转到页面重新加载或“超链接"上的“特定"选项卡,其中选项卡由AJAX加载

更新时间:2023-02-02 12:24:17

转到最后一个具有焦点的选项卡的唯一方法是存储引用(使用cookie或本地存储).

The only way to go to the last tab that has the focus, is to store a reference (using cookies or local storage).

此代码使用本地存储来存储焦点标签的href值,以后再检索它.

This code uses local storage to store the href value of the focused tab and later retrieve it.

$(function() { 
    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
        localStorage.setItem('focustab', $(e.target).attr('href'));
    });

    var focustab = localStorage.getItem('focustab');
    if (focustab) {
        $('[href="' + focustab + '"]').tab('show');
    }
});