我可以知道是什么错误导致我的输入字段无法输入字符吗?因为在输入字段中设置></\":*?|了这些符号限制后,其他字符无法在输入字段中输入。
<!DOCTYPE html>
<html>
<body>
<h1>Can't type character in the input field</h1>
<input type="text" class="form-control blank" id="function_code" name="function_code" title="function_code" onpaste="return false">
<div id="error-box"></div>
</body>
</html>
<script>
function showError (key) {
var errBox = document.querySelector("#error-box");
errBox.textContent = "The character " + key.toString() + " is not allowed!";
//Dismiss the error
window.setTimeout(function () {
errBox.textContent = "";
}, 10000)
}
document.getElementById("function_code").onkeypress = function(e) {
var chr = String.fromCharCode(e.which);
if ("></\":*?|".indexOf(chr) >= 0)
showError(chr)
return false;
};
</script>
希望有人能帮我解决这个问题。谢谢。
人到中年有点甜
隔江千里
相关分类