javascript - 按钮内的链接在 Firefox 中不起作用

标签 javascript html firefox button hyperlink

我在一个按钮中有两个链接,但这些链接在 Firefox 上似乎不起作用。

<button class="btn login">
    <a href="/login"><b>Log In</b></a> 
          | 
<a href="/signup"><b>Sign Up</b></a>
</button>

我尝试了 JavaScript onclick 和重定向 - 即使那样也不起作用。

最佳答案

这不起作用,因为 it is not allowed by HTML5 :

Content model: Phrasing content, but there must be no interactive content descendant.

Interactive content means any of the following elements :

a audio (if the controls attribute is present) button details embed iframe img (if the usemap attribute is present) input (if the type attribute is not in the hidden state) keygen label menu (if the type attribute is in the toolbar state) object (if the usemap attribute is present) select textarea video (if the controls attribute is present)

如果它在某些浏览器中确实有效,那只是因为他们试图 善待格式错误的标记并提供一些有意义的结果。

换句话说:重写你的 HTML,一团糟。如果您希望链接看起来像是在一个按钮中,请将它们放在一个 div 元素中,并将其设置为看起来像一个元素,而不是滥用语义错误的元素。

关于javascript - 按钮内的链接在 Firefox 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17253410/

相关文章:

javascript - 使用 JavaScript 对象构建菜单的最有效方式

javascript - 根据数组元素从数组中提取元素

javascript - InstantClick 未绑定(bind)到动态 href

javascript - 在表单中设置默认操作

javascript - 如何使用 nsIProcess 在 JavaScript 中运行没有窗口的 Windows 命令

css - 如何只为 Firefox 导入一个 css 文件,而不为其他浏览器导入?

javascript - 跟踪书签事件

javascript - 如何使滚动条长度小于父 block ?

javascript - 为智能手机制作动画 HTML 表格

firefox - 在 Firefox 开发者版本上显示 Firefox OS 开发工具 'desktop'