簡體   English   中英

如何通過jQuery重定向到html中附加的href?

[英]How can I redirect to the attached href in html via jQuery?

我想通過jQuery將我的網站重定向到代碼中附加的href。 因為我首先要播放動畫。


$(document).ready(function(){
  $("a").click(function(event){
    event.preventDefault();
    $('.preload').addClass('preload-loading')
        setTimeout(function(){

            url = location.href;
         $( location ).attr("href", url); <<-- I WANT TO REDIRECT TO THE PAGE THATS IN THE HREF IN THE HTML

        }, 500);

  });
});

使用window.location.href

window.location.href = $(event.target).attr("href");
  • 看下面的代碼可能會對你有所幫助

    $(document).ready(function(){ $("a").click(function(event){ var url = $(this).attr('href'); event.preventDefault(); $('.preload').addClass('preload-loading')
    setTimeout(function(){ window.location.href = url; // REDIRECT }, 500);
    }); });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM