【问题标题】:How to make href will work on button in IE8如何使href将在IE8中的按钮上起作用
【发布时间】:2010-06-01 13:01:43
【问题描述】:

我希望 href 可以在 IE8 中使用 type="button"

<a href="submit.php"><input type="button" value="Submit" class="button" /></a>

其他浏览器工作正常,但在 IE8 上上面的代码不起作用。如何解决?

更新

<form action="submit.php" method="post"">
<input type="submit" value="Submit" class="button" />
</form>

我知道可以这样做。但是我想知道其他方法如何使其在 IE8 上运行而无需 &lt;form&gt;&lt;/form&gt;

【问题讨论】:

  • 为什么不使用提交按钮而不是使用按钮?
  • 是可以做到的.. 但我想知道如何让它在 IE 上工作而无需提交表单

标签: html xhtml internet-explorer-8


【解决方案1】:

onclick="window.location=this.parentNode.href;"/>

this.parentNode 可以引用一个标签,所以......它应该可以工作或测试 getAttribute 甚至

【讨论】:

  • 现在不是 90 年代。永远不要永远不要使用 onclick。
【解决方案2】:

为什么不使用

<form action="submit.php" method="get">
<input type="button" value="Submit" class="button" />
</form>

?

【讨论】:

    【解决方案3】:

    我曾经很高兴 IE8 不是 IE6。但说真的。

    我正在使用 jQuery 修补 &lt;a&gt; 链接标签内的任何按钮标签,在条件标签内,因此它仅适用于旧 IE。

    <!--[if lt IE 9]>
    
    <script type="text/javascript">
    // IE8 is the new IE6. Patch up http://stackoverflow.com/questions/2949910/how-to-make-href-will-work-on-button-in-ie8
    $('button').click(function(){
        document.location = $(this).parents('a').first().prop('href');
    });
    </script>
    
    <![endif]-->
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-29
      • 2016-03-20
      • 1970-01-01
      • 1970-01-01
      • 2016-06-19
      • 2012-09-03
      • 1970-01-01
      • 2023-03-27
      相关资源
      最近更新 更多