【问题标题】:Redirect without loop无循环重定向
【发布时间】:2022-01-10 14:52:56
【问题描述】:

我有一个下拉菜单,可以抓取另一个下拉菜单的 href 并将其保存到变量中。如何在不循环的情况下使用 window.location.replace() 重定向页面。

let deutsch_link = '';
$('.lang_list_class li a').each(function() {
  if ($(this).text() == "Deutsch" || $(this).text() == "Deutsche" || $(this).attr("data-language") == "de") {
    deutsch_link = $(this).attr("href");
    console.log(deutsch_link);
    
    window.location.replace(deutsch_link);
         
  }
});

【问题讨论】:

    标签: loops redirect href


    【解决方案1】:

    windows.location.replace 正在那里执行重定向。 你可以试试

    $(this).attr("href", deutsch_link) 
    

    所以重定向发生在a 标签被实际点击时。如果没有,请让我了解更多有关要求的信息,也许我理解错误。

    【讨论】:

      猜你喜欢
      • 2014-03-18
      • 1970-01-01
      • 1970-01-01
      • 2013-01-25
      • 2012-06-08
      • 2019-08-31
      • 1970-01-01
      • 2015-01-26
      • 1970-01-01
      相关资源
      最近更新 更多