How to prevent page refresh when tag clicked?

前端 未结 4 551
眼角桃花
眼角桃花 2021-01-25 15:28

I need to pass a parameter into the URL and at the same time prevent page from reloading when I click any tag with a blank href attribute (

4条回答
  •  [愿得一人]
    2021-01-25 16:17

    Try the following code

      $('.list-group-item a').click(function (event) {
       event.preventDefault();
       var url = $(this).attr('href');
       window.history.replaceState("object or string", "Title",url); // this will change your url
     });
    

    For More details http://spoiledmilk.com/blog/html5-changing-the-browser-url-without-refreshing-page/

提交回复
热议问题