通过单击一个按钮,url必须更改,但html应该保持不变
$('#v-pills-profile-tab').on('click', function (event) {
// change url
// and html remains
})
您可以使用history.pushState()和windowEventHandlers.onpopState
<button id="v-pills-profile-tab"> TEST ME </button>
<script>
$('#v-pills-profile-tab').on('click', function (event) {
window.history.pushState({data: "some data that i will need"}, "", "my-new-url");
});
window.onpopstate = function (e) {
if (e.state) {
console.log(e.state.data);
} else {
window.location.reload();
return;
}
};
</script>
要更改url,您可以简单地执行以下操作:
window.location = //Your url here
另外,为了重新加载页面,您可以简单地使用:
window.location.reload()
当您更改url时,页面会自行重新加载自己。 你不需要重新加载它