简体   繁体   中英

I have a login form with an event of clicking the enter key to submit the form, it is not working in IE

I have a login form with an event of clicking the enter to submit the form, it is not working in IE

<form name="login" action="" method="post">
<ul>
    <li class="col1">E-mail Address</li>
    <li class="col2"><input name="email_address" type="text" class="textfiled" /></li>
    <li class="col1">Password</li>
    <li class="col2"><input name="password" type="password" class="textfiled" /></li>
    <li class="col1"></li>
    <li class="col2"><input name="signin" type="button" class="signin-btn" onclick="javascript: login.submit();" onkeydown="javascript: if (window.event.keyCode == 13) login.submit(); else window.event.keyCode = null;"/></li>
</ul>
</form>

Here on submit button i have mention an event as onkeydown="javascript: if (window.event.keyCode == 13) login.submit(); else window.event.keyCode = null;"

This is not working in IE, can someone suggest me any solution for this or any alternative of solution i have applied for my requirement?

Any reason why you're not using a simple

<input type="submit">

?

It should enable the "enter to submit" behaviour in all browsers without having to use JavaScript at all.

您应该将onkeydown事件移动到文本字段,而不是将其放在按钮控件上。

除了尖刺答案,您还可以观察整个表单的onkeydown:

<form onkeydown="(function(event,form){if(event.keyCode == 13){form.submit();}})(event,this)" name="login" action="" method="post">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM