【问题标题】:Button link doesn't work in Firefox, IE按钮链接在 Firefox、IE 中不起作用
【发布时间】:2018-06-13 06:00:28
【问题描述】:

我的链接在 Chrome 中可以正常工作,但在 IE 或 Firefox 中不行。如果您单击它们,则不会发生任何事情。我已经搞砸了 CSS(包括 z-index),但我没有想法。这是来自 Drupal 的 XHTML。

html 看起来像这样:

<div class="product-display-block-link">
  <button>
    <a href="/checkout/outfield-banner/1">Add to cart</a>
  </button>
</div>

有什么建议可以去哪里看吗?

【问题讨论】:

  • 我怀疑你的href中的路径。结帐是否在同一个文件夹中?

标签: html


【解决方案1】:

HMTL 语法不允许在button 元素中包含a 元素,因此它不能跨浏览器工作也就不足为奇了。应该没有理由使用这样的结构,因为您可以将链接设置为看起来像按钮,也可以将操作与按钮相关联,具体取决于您希望完成的任务。

【讨论】:

  • “或将动作与按钮相关联” - 你能举个例子吗?
  • 示例:&lt;button onclick="window.location='/checkout/outfield-banner/1'"&gt;Add to cart&lt;/button&gt;.
【解决方案2】:

如果您想要一个按钮(即提交表单或悬挂 JavaScript 的东西),请使用按钮。如果需要链接,请使用链接。如果您想要一个看起来像按钮的链接,请使用一个链接,然后将其样式设置为您想要的样式。

您不能将两者混用,因为 &lt;button&gt; 元素不允许包含 &lt;a&gt; 元素。元素的definition 明确排除它们:

<!--
 Content is %Flow; excluding a, form and form controls
--> 
<!ELEMENT button %button.content;>  <!-- push button -->

<!ENTITY % button.content
   "(#PCDATA | p | %heading; | div | %lists; | %blocktext; |
    table | %special; | %fontstyle; | %phrase; | %misc;)*">

【讨论】:

  • 这也是真的in HTML5,不仅仅是XHTML1.0。
  • 在 (X)HTML 的每个版本中都是如此。我刚刚引用了 XHTML 1.0,因为问题提到了 XHTML。
【解决方案3】:

&lt;button&gt; 没有被正确使用。

HTML:

 <div class="product-display-block-link">
    <button onClick="javascript: window.location='/checkout/outfield-banner/1'">Add to Cart</button>
</div>

在此处查看实际操作:http://jsfiddle.net/s8jtf/

【讨论】:

  • 不知道为什么你被否决了,这正是我想要的。
【解决方案4】:

我有类似的情况,在这里发布了我的问题 => Why does Dreamweaver cc16, Bootstrap v3.3.6, created, hyperlinked Button work in Opera & Chrome but not IE or Firefox?

这是我的 Button 原始代码 =>

The Button html code is: =>

<div align="center" style="font-size: 1.5em"> <button type="button" class="btn btn-lg"> <a href="https://howtoliveoffthegridnow.com/wordpress/get-your-own-off-the-grid-checklist/" title="Access option to download checklist"><strong>FREE: 11 Things To Know Before Going Off The Grid</strong></a> </button> </div>

相关的 bootstrap.css v3.3.6 通常使用以下方式链接:=>

&lt;link rel="stylesheet" type="text/css" href="assets/css/bootstrap.css" /&gt;

这在 Chrome 和 Opera 中有效,但在 IE 或 Firefox 中无效,但显然它不应该在任何浏览器中有效。

这是我将 Button 代码元素更改为 =>

`<div class="btn btn-lg" style="background-color:#ffffff;">
 <a href="https://howtoliveoffthegridnow.com/wordpress/get-your-own-off-the-grid-checklist/" title="Access option to download checklist"><strong>FREE: 11 Things To Know Before Going Off The Grid</strong></a>

这适用于所有浏览器。 /psb

【讨论】:

    【解决方案5】:

    另外,缺少类型属性。不同的浏览器假设不同的类型,例如,不一定 type="submit"。

    【讨论】:

    • 如果浏览器不假定提交,那么它就坏了。无论如何,这可能无关紧要,因为似乎没有涉及任何形式。
    • 不幸的是,需要考虑浏览器的差异。至于提交不相关,我认为表单可能是解决方案之一,因为它可以在没有 javascript 的情况下工作(当然,这可能相关或不相关)。
    猜你喜欢
    • 2023-03-28
    • 2013-06-19
    • 2018-04-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多