按钮标记不起作用

时间:2016-02-26 10:55:36

标签: html5

我想将<button>代码重定向到特定的网页/网址。我不确定我的代码有什么问题。

<button onclick="location.href='http://google.com';" value="Go to Google">Take Me To Google</button>

这是我正在使用的代码。它不像我们使用输入&amp;标签

2 个答案:

答案 0 :(得分:0)

试试这个

<button type="button" onclick="location.href='http://www.google.com';" value="Google">
  Google
</button>

答案 1 :(得分:0)

无法导航到另一个网址,该网址因其受到保护而限制其他网域访问这些网址。

  

此问题通常被称为跨源资源共享(C.O.R.S.)。您可以深入了解here

在众多中, Google 就是其中之一。

您可以尝试将Google中的网址替换为其他网址,例如bing: - &gt;

<button type="button" onclick="location.href='https://www.bing.com';" value="Bing">Bing</button>

它会起作用,因为,bing允许其他网址在没有任何C.O.R.S的情况下访问它。

就您的code而言,我发现您的代码没有任何问题。

希望这个答案可以帮到你。