实践练习:排序并显示名字
<script type="text/javascript" language="JavaScript">
var numnames=0;
var names = new Array();
function SortNames() {
thename = document.theform.newname.value;
names [numnames] = thename;
numnames++;
names.sort();
document.theform.sorted.value=names.join("\n");
}
</script>
<h3>string Array</h3>
<p>Enter tow 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>Sorte Names</h3>
<textarea cols='60' rows='10' name="sorted">
The sortes names will appear here.
</textarea>
</form>