搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

Javascript not working in Firefox,chrome,opera but works in IE

  • 2 回覆
  • 21 有這個問題
  • 6 次檢視
  • 最近回覆由 cor-el

more options

This or any other program shows nothing on screen.


<!DOCTYPE html>
<html>
<head>
	<title> Epic! </title>
</head>
<body>
<script type="text/javascript">

var name = new Array("jon","cody","molly");
name.sort();
for (j=0;j<name.length;j++){
document.write(name[j] + "<br>");
}


</script>
</body>
</html>

................................................................................................................................
this say 
,,Undefined

<!DOCTYPE html>
<html>
<head>
	<title> Epic! </title>
</head>
<body>
<script type="text/javascript">

var name = new Array(3);
for (j=0;j<3;j++){
name[j] = prompt ("enter 3 names " ,"");
}
document.write(name[0] + name[1] + name[2]);



</script>
</body>
</html>
This or any other program shows nothing on screen. <pre><nowiki><!DOCTYPE html> <html> <head> <title> Epic! </title> </head> <body> <script type="text/javascript"> var name = new Array("jon","cody","molly"); name.sort(); for (j=0;j<name.length;j++){ document.write(name[j] + "<br>"); } </script> </body> </html> ................................................................................................................................ this say ,,Undefined <!DOCTYPE html> <html> <head> <title> Epic! </title> </head> <body> <script type="text/javascript"> var name = new Array(3); for (j=0;j<3;j++){ name[j] = prompt ("enter 3 names " ,""); } document.write(name[0] + name[1] + name[2]); </script> </body> </html></nowiki></pre>

由 cor-el 於 修改

所有回覆 (2)

more options

hi Jon92, support.mozilla.org is intended for end-user support. if you have a question regarding web development please refer to Where to go for developer support instead. thank you for your understanding!

more options

That is because "name" is a reserved variable name and can't be used. Just choose something else for the variable name and it will work ('Name' works, may fail in a future Firefox version). You should always be cautious when you choose a common name as the name of a variable as such a name may become reserved.


Web Console: TypeError: name.sort is not a function

由 cor-el 於 修改