Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
374 views
in Technique[技术] by (71.8m points)

html - JavaScript function causing all other functions not to work inside js file

In safari 4 and all explorer browsers, whenever I try to call a function inside a javascript file which contains this function below, that first function isn't called.

So calling function1 will not work if function2 is inside the same .js file, explanation?

Here is the code which makes the problem. Whenever I remove this function, everything works fine and all functions work fine. So this function is causing a problem.

 function addOption(selectbox, value, text, class, id_nr )
 {
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
optn.id = value;
if (class==1){ optn.className = "nav_option_main"; }
selectbox.options.add(optn);
 }

Any ideas why?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Maybe it gets upset because you use a reserved word (class) as a variable identifier. Try using klazz or something else.

Here is a link to a list of reserved words: en.wikibooks.org/wiki/JavaScript/Reserved_Words
And here's some words from Monsieur Crockford (scroll down or search for the phrase "JavaScript is very heavy handed in its restrictions on reserved words"): crockford.com :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...