[英]keyListener “Enter” doesn't work
function checkId() {
var password = document.getElementById("passwordBox").value;
if (password == "superx") {
return true;
};
alert("Not Allowed :(");
return false;
};
function keyAdd() {
passwordBox.addEventListener("keypress", function(event) {
if (event.keyCode == 13) {
checkId();
}
})
};
What's the problem in the second function? 第二个功能有什么问题?
1) https://www.w3schools.com/Jsref/event_onkeypress.asp said : " Note: The addEventListener() method is not supported in Internet Explorer 8 and earlier versions. " try : " object.onkeypress = function(){myScript}; " instead... 1) https://www.w3schools.com/Jsref/event_onkeypress.asp说:“ 注意: Internet Explorer 8和更早版本不支持addEventListener()方法。 ” try:“ object.onkeypress = function(){ myScript}; “而是...
2)maybe you don't call "keyAdd()" at all... 2)也许您根本不调用“ keyAdd()” ...
You can try it 你可以试试
<script> function checkId() { var password = document.getElementById("passwordBox").value; if (password == "superx") { return true; } alert("Not Allowed :("); return false; }; function keyAdd() { passwordBox.addEventListener("keypress", function(event) { if(event.keyCode == 13){ checkId(); } }) }; </script>
<input type="password" name="passwordBox" id="passwordBox" onkeypress="return keyAdd(event)"/>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.