【发布时间】:2015-12-22 11:16:38
【问题描述】:
我正在努力学习 JavaScript,我正在关注 Michael Moncur JavaScript 的 24Hr 第 4 版。本书中的一个示例如下所示,假设对一组名称进行排序。但是当我点击按钮时什么都没有发生。代码是正确的还是书已经过时了。
名为 sort.html 的 HTML 文件
<html>
<head>
<title>Array Sorting Example</title>
<script type="text/javascript" language="javascript" src="sort.js">
</script>
</head>
<body>
<h1>Sorting String Arrays</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>
这是 JS 文件名 sort.js
// initialize the counter and the array
var numnames=0;
var names = new Array();
function SortNames() {
// Get the name from the text field
thename=document.theform.newname.value;
// Add the name to the array
names[numnames]=thename;
// Increment the counter
numnames++;
// Sort the array
names.sort();
document.theform.sorted.value=names.join(“\n”);
}
任何想法有什么问题
【问题讨论】:
-
在 24 小时内学习某事,很可能导致只制作需要 24 小时顶级的东西,除此之外,当然,如果你用 光速 学习 :)
标签: javascript html