js文档排序不起作用
js document sort not working
我正在努力学习JavaScript,我正在关注Michael Moncur JavaScript第4版《24小时》。下面是书中的一个例子,假设将一组名称按顺序排序。但当我点击按钮时,什么也没发生。代码是正确的还是这本书过时了。
名为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”);
}
任何想法出了什么问题
document.theform.sorted.value=names.join("'n");
问题是你使用的是印刷多宝引号。
如果将“
替换为"
,将起作用。
相关文章:
- 为什么我的JavaScript堆栈排序函数不起作用
- Rubaxa可与聚合物进行排序/拖放不起作用,具体取决于显示器:
- 我在页面中使用的jQuery UI可排序项目;不起作用
- jquery中DataTables插件中的排序不起作用
- jQuery dataTables基于类型的列筛选不起作用?Img alt过滤器/排序
- 为什么这个排序函数不起作用
- 为什么这个排序功能在 Safari 中不起作用
- JavaScript排序算法不起作用 - 任何明显的我做错了
- j查询排序不起作用
- 网页按价格排序下拉菜单不起作用
- 表排序器寻呼机在调查视图上不起作用
- 为什么这种 jquery 驱动的表排序不起作用
- jQuery DataTables排序不起作用
- D3中的排序条形图不起作用
- populate中的Mongoose排序不起作用
- 表排序在IE 7中不起作用
- 使用J-query数据表,美国日期格式的自定义排序不起作用
- jQuery 表排序器排序不起作用
- 我的Javascript(用于在ul中重新排序li)在IE中不起作用
- 从 AJAX 调用的 PHP 对数组进行排序不起作用