gpt4 book ai didi

Javascript,设置允许的字符函数

转载 作者:行者123 更新时间:2023-12-03 01:26:44 26 4
gpt4 key购买 nike

当我将设置的“允许的字符函数”放入我的 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;
}

最佳答案

您缺少)

改变

if (allow == 'Letters'{AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';}
^
missing ) here

if (allow == 'Letters'){AllowableCharacters=' ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';}
^
put it here

您应该使用浏览器控制台来处理这些错误,因为它会向您显示它们的位置和内容

关于Javascript,设置允许的字符函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51502771/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com