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();
}
})
};
第二个功能中的问题是什么?
答案 0 :(得分:0)
1)https://www.w3schools.com/Jsref/event_onkeypress.asp说:" 注意: addEventListener()方法不支持在Internet Explorer 8及更早版本中。"尝试:" object.onkeypress = function(){myScript}; "代替...
2)也许你不打电话给#34; keyAdd()"在所有......
答案 1 :(得分:0)
你可以尝试一下
<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)"/>