使用在你的CSS一display: none;
:
#popup {
display: none;
}
然后使用您的JS其中任何一项:
$("#open").on('click', function(e) {
e.preventDefault();
$("#popup").toggle(); //When clicked, toggle visibility.
});
$(window).on('hashchange', function() {
//You can detect a hash change like this
//Since your href is set to #popup,
//you can put the .toggle() in here as the hash will change when clicked.
console.log("yolo");
});
if(window.location.hash == "#popup") {
//If it is initialized with the hash #popup (ie. example.com#popup and Enter)
//Use this
console.log("yolo2");
$("#popup").show();
}
逸Fiddle