当我将设置的“允许的字符功能”放入我的javascript文件中时,“窗口加载功能”不再起作用。谁能发现什么地方出问题了?
// --- ACTIVATES THE ON LOAD FUNCTION ---
function init(){
alert('ENTERED ON LOAD FUNCTION');
myFunction_AlertThree();
}
window.onload = init;
// ---> TESTING ONLY
function myFunction_AlertThree() {
alert('entered alert THREE function.');
}
//----------- SET ALLOWABLE CHARACTERS FUNCTION -----------
function inputLimiter(e,allow) {
var AllowableCharacters = '';
if (allow == 'Letters'{AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';}
if (allow == 'Numbers'){AllowableCharacters='1234567890';}
if (allow == 'NameCharacters'){AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz -.\'';}
if (allow == 'NameCharactersAndNumbers'){AllowableCharacters='1234567890 ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-.\'';}
if (allow == 'Currency'){AllowableCharacters='1234567890.';}
var k = document.all?parseInt(e.keyCode): parseInt(e.which);
if (k!=13 && k!=8 && k!=0){
if ((e.ctrlKey==false) && (e.altKey==false)) {
return (AllowableCharacters.indexOf(String.fromCharCode(k))!=-1);
} else {
return true;
}
} else {
return true;
}
}
答案 0 :(得分:1)
您缺少)
更改
if (allow == 'Letters'{AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';}
^
missing ) here
到
if (allow == 'Letters'){AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';}
^
put it here
您应该使用浏览器控制台来处理这些错误,因为它会告诉您它们的位置和含义