在IE8中输入一个表格不起作用 [英] In IE8 enter key in a form does not work

查看:152
本文介绍了在IE8中输入一个表格不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题,在IE8中输入无法提交表单。我已经生成了一个测试页面来揭示这个问题。看起来,在 onLoad 函数中显示表单会禁用 enter 按钮不会触发提交的结果。这是一个在IE8中的错误,或者它是一些安全问题?



重现这一点的代码是:

 onload = function(){document.getElementById('test')。style.display ='block'; }  

  #test {display:none;} < form id =testmethod =getaction =  

 


解决方案

一个合适的解决方案,并希望它分享与你们。



而不是使用< input type =submit ...> ,使用< button type =submit...>
这在其他浏览器(IE6 - )

 <!DOCTYPE HTML PUBLIC -  // W3C // DTD HTML 4.01 // ENhttp://www.w3.org/TR/html4/strict.dtd\"> 
< html>
< head>
< style type =text / css>
#test {
display:none;
}
< / style>
< ; script type =text / javascript>
onload = function(){
document.getElementById('test')。style.display ='block';
};
< / script>
< / head>
< body>
< form id =testmethod =getaction =javascript:alert('woei !')>
< input type =textname =uservalue =/> ;
< input type =passwordname =pwvalue =/>
< button type =submitvalue =submitid =submit>< / button>
< / form>
< / body>
< / html>


I have a problem that in IE8 the enter does not work to submit a form. I have generated a test page to expose this problem. It seems that displaying the form in the onLoad function disables results that the enter button does not trigger a submit anymore. Is this a bug in IE8 or is it some security issue?

The code to reproduce this is:

onload = function() { 
    document.getElementById('test').style.display = 'block'; 
} 

#test {
    display: none;
}

<form id="test" method="get" action="javascript:alert('woei!')"> 
    <input type="text" name="user" value=""> 
    <input type="password" name="pw" value="">
    <input type="submit" value="submit" id="submit"> 
</form> 

解决方案

I have found a proper solution and wanted it to share with u guys.

Instead of using <input type="submit...>, use <button type="submit"...>. This will do exactly the same in the other browsers (IE6-7, FF3) AND works in IE8. :)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
<head> 
<style type="text/css">
#test {
    display: none;
} 
</style> 
<script type="text/javascript"> 
onload = function() { 
    document.getElementById('test').style.display = 'block'; 
};
</script> 
</head> 
<body> 
<form id="test" method="get" action="javascript:alert('woei!')"> 
    <input type="text" name="user" value="" /> 
    <input type="password" name="pw" value="" />
    <button type="submit" value="submit" id="submit"></button>
</form> 
</body> 
</html>

这篇关于在IE8中输入一个表格不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆