我在一个按钮中有两个链接,但这些链接在 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/