【问题标题】:How can I redirect to the attached href in html via jQuery?如何通过jQuery重定向到html中附加的href?
【发布时间】:2019-09-04 00:25:49
【问题描述】:

我想将我的网站重定向到 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);

  });
});

【问题讨论】:

  • location 中的$( location ) 是什么

标签: javascript jquery html css redirect


【解决方案1】:

使用window.location.href:

window.location.href = $(event.target).attr("href");

【讨论】:

    【解决方案2】:
    • 看下面的代码可能对你有帮助

      $(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);
      }); });

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-24
      • 2015-11-29
      • 2016-08-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多