简体   繁体   中英

internet explorer text input onkeyup char 13

the onkeyup event does not seem to be called for IE8/IE9 (I don't know about 10) when we press the enter button on an input box, if in the page there is a button element.

<html>
<head>
<script>
function onku(id, e) {
    var keyC = 0;
    keyC = e.keyCode ? e.keyCode : e.charCode;
    document.getElementById("mydiv").innerHTML += keyC + "<br>";
}
</script>
</head>
<body>
<button type="submit" >Test Button</button>
<input type="text" maxlength="5" onkeyup="onku(id, event);">
<br>
<div id="mydiv"><div>
</body>
</html>

so for every input onku() will be called, but not on ENTER ( keyC = 13 ). Now, if i remove the

<button type="submit" >Test Button</button>

button, it will fire. Anyone knows why ?

No other browser has the problem.

jsfiddle: http://jsfiddle.net/ssmpM/

我只需要删除type="submit"

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