错误:[函数]未定义
我收到了一个未定义的函数错误,我一生都无法弄清楚。这个脚本有什么问题?
var numnames=0;
var names=new Array();
function SortNames(){
thename=document.theform.newname.value;
numnames++;
names.sort();
document.theform.sorted.value=names.join("\n");
}
我在这里调用代码:
<html>
<head></head>
<body>
<script type="text/javscript" language="javascript" src="sort.js">
</script>
<h1>Sorting Array</h1>
<p>Enter two or more names in the field below, and the sorted list of names will appear in the text area<p>
<form name=theform>
Name:
<input type=text name=newname size=20>
<input type=button name=addname value=Add onclick="SortNames();">
<br/>
<h2>Sorted Names</h2>
<textarea cols=60 rows=10 name=sorted>
The sorted names will appear here
</textarea>
</form>
</body>
</html>
我得到的错误是SortNames is not Defined
。
I'm getting an undefined function error that for the life of me I can't figure out. What is wrong with this script?
var numnames=0;
var names=new Array();
function SortNames(){
thename=document.theform.newname.value;
numnames++;
names.sort();
document.theform.sorted.value=names.join("\n");
}
I call the code here:
<html>
<head></head>
<body>
<script type="text/javscript" language="javascript" src="sort.js">
</script>
<h1>Sorting Array</h1>
<p>Enter two or more names in the field below, and the sorted list of names will appear in the text area<p>
<form name=theform>
Name:
<input type=text name=newname size=20>
<input type=button name=addname value=Add onclick="SortNames();">
<br/>
<h2>Sorted Names</h2>
<textarea cols=60 rows=10 name=sorted>
The sorted names will appear here
</textarea>
</form>
</body>
</html>
The error I get is SortNames is not defined
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你能尝试改变:
到 吗
?
并使用调试器检查您的浏览器是否可以找到 sort.js。
Could you try changing:
To
?
And check if your browser can find sort.js using the debugger.
您的代码看起来不错,要么您使用的是较旧的浏览器,要么错误出现在代码的另一部分。尝试将文件减少到测试所需的最低限度,或使用 javascript 控制台跟踪其他错误。
Your code looks fine, either you are using an older browser or the error is in another part of your code. Try to reduce your file to the bare minimum needed to test or use the javascript console to track down other errors.