发现没有用<Form>标签和form.submit方法的回车提交在firefox下面不工作,因为FireFox不捕捉回车事件。一般在IE下实现回车可以这样:
<INPUT TYPE=text NAME="hanbai_cd" SIZE=20 maxlength = 8 onkeydown=KeyDown()>
1: function KeyDown()
2: {
3: if (event.keyCode == 13)
4: {
5: event.returnValue=false;
6: event.cancel = true;
7: Form1.btnsubmit.click();
8: }
9: }
上面只针对IE, 在firefox下面不工作,因为FireFox不捕捉回车事件,FF和IE兼容代码如下:
1: <script type="text/javascript">
2: <!--
3:
4: if(document.addEventListener){//如果是Firefox
5: document.addEventListener("keypress",fireFoxHandler, true);
6: }else{
7: document.attachEvent("onkeypress",ieHandler);
8: }
9:
10: function fireFoxHandler(evt){
11: //alert("firefox");
12: if(evt.keyCode==13){
13: validateLogon();//你的代码
14: }
15: }
16:
17: function ieHandler(evt){
18: //alert("IE");
19: if(evt.keyCode==13){
20: validateLogon();//你的代码
21: }
22: }
23:
24: //-->
25: </script>