Html <button> 在 IE8 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7062061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 10:04:18  来源:igfitidea点击:

<button> not working in IE8

htmlbuttoninternet-explorer-8tags

提问by David

I have a number of buttons on my website using the button tag, and while rendering fine on IE8, they are not clickable (clicking them doesn't send the user to the new url). Are there any solutions to fix this for IE? Is it because I'm wrapping the button in an tag? Is it because I'm using a class name of "button"?

我的网站上有许多按钮使用 button 标签,虽然在 IE8 上呈现良好,但它们不可点击(点击它们不会将用户发送到新的 url)。是否有任何解决方案可以为 IE 解决此问题?是因为我将按钮包装在标签中吗?是因为我使用了“按钮”的类名吗?

The code is:

代码是:

<a href="product_home.html">
<button class="button green big_button">Learn more</button>
</a> 

采纳答案by Esko

Your markup is wrong, IE is not in fault here. Button is a form element which means that it requires a form around it point where the user should be sent - wrapping the button into a link tag isn't enough nor exactly valid, in fact I don't think it should work anywhere, not even in other browsers.

你的标记是错误的,IE 没有错。Button 是一个表单元素,这意味着它需要一个围绕它发送用户的点的表单 - 将按钮包装到链接标签中是不够的,也不完全有效,事实上我认为它不应该在任何地方工作,而不是即使在其他浏览器中。

To read more about correct usage of <button/>, visit XHTML Reference: button

要阅读有关 正确用法的更多信息<button/>,请访问XHTML 参考:按钮

回答by Dan Williams

You could always use Javascript, which works cross browser -

你总是可以使用 Javascript,它可以跨浏览器工作 -

<button onclick="location.href='http://www.google.com'">This is a button to google</button>

回答by Biz Web

Cross Browser - works in MSIE 8 and FF 24+

跨浏览器 - 适用于 MSIE 8 和 FF 24+

<button onclick="location.href='myscript.php?id=$ID'" type="button">MyLink</button>.

回答by jchysk

You could try:

你可以试试:

<a href="product_home.html" class="button green big_button">Learn more</a> 

or putting the button in a form

或将按钮放入表单中

回答by Nathan

See my other answer; I think this is a modern jQuery-based approach to patching this issue for old IEs, without mangling your nice clean markup.

我的另一个答案;我认为这是一种基于 jQuery 的现代方法,可以为旧 IE 修补此问题,而不会破坏您漂亮的干净标记。

<!--[if lt IE 9]>

<script type="text/javascript">
// IE8 is the new IE6. Patch up https://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]-->

回答by user1883212

<a href="product_home.html">
<div class="button green big_button">Learn more</div>
</a> 

回答by Jeff Clayton

sample usage:

示例用法:

<form id="myform" name="myform" action="product_home.html">
  <input id="user" name="user" type="text" value="" />
  <button class="button green big_button" type="submit">Learn more</button>
  <button class="button green big_button" type="reset"><b>reset the form!</b></button>
</form>

<script type="text/javascript">

var myform = document.getElementById('myform');

myform.onsubmit = function()
{
    alert(myform.user.value); 
if (myform.user.value != '') return true;
    return false;
}

</script>