首页上一页 1 下一页尾页 1 条记录 1/1页
关于《Javascript从入门到精通》P116中的sort()和reverse()的用法
发表在Java图书答疑
2012-12-18
是否精华
是
否
版块置顶:
是
否
您好,我看了该书P116页的案例,自己试做了一个案例,但没有做好,在屏幕输出不了。现在请教您。代码如下:
<body>
<script type="text/javascript">
var Names = new Array("3:何贵明","2:方燕","5:熊伟","1:陈兵","6:张三","4:李四");
var ord = prompt("Enter 1 for number order ,and -1 for reverse order",1);
if (ord == 1)
{
Names.sort();
document.write(+Names+("<br />"));
}
else if(ord == -1)
{
Names.sort();
Names.reverse();
document.write(+Names("<br />"));
}
else
{
document.write("that is not a valid input");
}
</script>
</body>
<body>
<script type="text/javascript">
var Names = new Array("3:何贵明","2:方燕","5:熊伟","1:陈兵","6:张三","4:李四");
var ord = prompt("Enter 1 for number order ,and -1 for reverse order",1);
if (ord == 1)
{
Names.sort();
document.write(+Names+("<br />"));
}
else if(ord == -1)
{
Names.sort();
Names.reverse();
document.write(+Names("<br />"));
}
else
{
document.write("that is not a valid input");
}
</script>
</body>