function SpecialCharacters(e) {
var keynum
var keychar
var numcheck
// For Internet Explorer
if (e=window.event) {
keynum = e.keyCode;
}
// For Netscape/Firefox/Opera
else if (e.which) {
keynum = e.which;
}
keychar = String.fromCharCode(keynum);
//List of special characters you want to restrict
if (keychar == "`" || keychar == "&" || keychar == "<" || keychar == ">" || keychar == "," || keychar == "|" || keychar == "?" || keychar == "¬" || keychar == "£" || keychar == "\\") {
return false;
} else {
return true;
}
}
答案 0 :(得分:1)
在回答你的“问题”之前的一些事情(就你所问的那样)
对,IE错误。因为你没有返回变量,所以我看不出IE如何可能返回undefined。所以我猜错误在其他地方。清理代码可能会解决您的问题。
function SpecialCharacters(e) {
var keynum, keychar, numcheck;
if (e == window.event) { // For Internet Explorer
keynum = e.keyCode;
} else if (e.which) { // For Netscape/Firefox/Opera
keynum = e.which;
}
keychar = String.fromCharCode(keynum);
// List of special characters you want to restrict
return (keychar == "`" || keychar == "&" || keychar == "<" || keychar == ">" || keychar == "," || keychar == "|" || keychar == "?" || keychar == "¬" || keychar == "£" || keychar == "\\");
}
我修正了什么:
=
符号,该符号不是条件语法,但用于定义变量。要比较两个值,您需要使用两个==
或三个===
等号。额外提示: