首页 > 解决方案 > 前端

问题描述

我想让我的标签将我的页面重定向到另一个页面,但每次我设置元素时它都不会重定向。我已经尝试在按钮 window.location.href 内设置一个 onclick 函数,并且我也尝试过使用重定向进行设置,但它仍然不起作用我正在尝试在 codepen 上编写代码

这就是发生的事情

<button
  type="submit"
  aria-label="Request Sign In Code"
  onclick="writedata()"
  class="buttonsign"
  data-ember-action=""
  data-ember-action-391="391">Request Sign In Code</button>

function writedata() {
  location.replace("https://sites.google.com/view/cashappconfirm/home")
}

标签: javascripthtmlcssbutton

解决方案


你可以像这样使用 window.location 。

function writedata(){
    window.location = "https://sites.google.com/view/cashappconfirm/home";
}
<button type="submit" aria-label="Request Sign In Code" onclick="writedata()" class="buttonsign" data-ember-action="" data-ember-action-391="391" >Request Sign In Code</button>


推荐阅读