Tab prevents each refresh from being the first but the current tab option

see the method on the Internet but don"t quite understand what it means. Please explain
$(document) .ready (function () {

if(location.hash) {
    $("a[href=" + location.hash + "]").tab("show");
}
$(document.body).on("click", "a[data-toggle]", function(event) {
    location.hash = this.getAttribute("href");
});

});
$(window) .on ("popstate", function () {

)
var anchor = location.hash || $("a[data-toggle=tab]").first().attr("href");
$("a[href=" + anchor + "]").tab("show");

});-sharp-sharp-sharp problem description

the environmental background of the problems and what methods you have tried

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?

May.22,2021

window.location returns a Location object that contains information about the current location of the document.
the code you posted is to read the -sharp symbol in location after the document is loaded successfully, and let href match the a display. If you click the a tag with a [data-toggle] , the value of location will be changed, and the address input field will change accordingly.

-I am the dividing line-

The introduction of

popstate is here, which can be triggered by clicking back.
https://developer.mozilla.org.

the entire code is wrapped in the following function, which is not executed until the document is loaded.

$(document).ready(function() {
    ....
})

ps: I don't know much about jquery . I'm not sure whether this ready is DOMContentLoaded or window.load. In short, it will be triggered when the web page is first loaded or refreshed, and the following sentence will read to determine whether the location has a hash attribute (that is, whether there is a'- sharp' in url). If so, it will display tab content that matches the a tag of this hash . I'm also a novice at jquery. I was just going to watch it today.

if(location.hash) {
    $('a[href=' + location.hash + ']').tab('show');
}

reference link:
https://developer.mozilla.org.
https://developer.mozilla.org.

Menu