在所选选项卡上重新加载在 IE 中不起作用

Reloading on the selected tab doesn't work in IE

我的网页上有 2 个选项卡:付款和对帐单。 当我重新加载同一页面时,我使用以下代码自动切换到选定的选项卡。

$('#advancedSearchTabs a').click(function(e) {
        e.preventDefault();
        $(this).tab('show');
    });

    // store the currently selected tab
    $("ul.nav-tabs > li > a").on("shown.bs.tab", function(e) {
        var id = $(e.target).attr("href").substr(1);
        window.location.hash = id;
    });

    // on load of the page, switch to the currently selected tab
    var hash = window.location.hash;
    $('#advancedSearchTabs a[href="' + hash + '"]').tab('show');

这适用于除 Internet Explorer 11 之外的所有浏览器。我总是跳回到第一个选项卡。我怎样才能在 Internet Explorer 中使用它

确保您为 IE 正确获取事件目标。

$("ul.nav-tabs > li > a").on("shown.bs.tab", function(e) {
  var target = e.target || e.srcElement; //srcElement for IE
  var id = target.getAttribute("href"); //No need for jQuery here
  history.pushState('','',id); //Try pushState
});

var hash = (location.href.split("#")[1] || ""); //Crossbrowser compatible
$('#advancedSearchTabs a[href$="' + hash + '"]').tab('show'); //Add $ to href attribute ends with "hash"

JavaScript event.target and event.srcElement