[英]Append Url via replaceState prevent Page Reloading
I have a code below that appends the url. 我下面有一个附加网址的代码。 The code works as it should.
该代码可以正常工作。 However, the replaceState didn't work as I thought it would.
但是,replaceState并未按我认为的那样工作。 Basically, I just want the page not to reload/refresh when the url is appended with text.
基本上,我只希望在URL后面附加文本时不重新加载/刷新页面。 Any suggestions how to fix this?
任何建议如何解决此问题?
<script>
$(document).ready(function() {
$("#staff-list").on('change', function() {
history.replaceState(null, null, location.href = "?account=" + $(this).val());
});
});
</script>
I just figured it. 我只是想通了。 I'll post here anyway for future coder who happens to seek for answers with similar issue.
无论如何,我都会在这里张贴文章供将来遇到类似问题的程序员使用。
<script>
$(document).ready(function() {
$("#staff-list").on('change', function() {
history.replaceState(null, null, "?account=" + $(this).val());
});
});
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.