简体   繁体   中英

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. Basically, I just want the page not to reload/refresh when the url is appended with text. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM