您的位置:首页 > Web前端 > JavaScript

关于JavaScript学习过程中的一些需要注意的点~~~

2014-05-30 11:09 417 查看


1.关于一个实现数组降序排列的方法

arrayObject.sort(方法函数)

1.如果不指定<方法函数>,则按unicode码顺序排列。
2.如果指定<方法函数>,则按<方法函数>所指定的排序方法排序。

<span style="color:#1f2426;"><!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Array对象 </title>
<script type="text/javascript">
function sortNum(a,b) {</span><span style="color:#ff0000;">//注意这里是实现降序排列的函数,关键是要注意这种方法~~</span><span style="color:#1f2426;">
return b-a;
}
var myarr = new Array("80","16","50","6","100","1");
document.write(myarr.sort(sortNum));
</script>
</head>
<body>
</body>
</html></span>
<span style="color:#1f2426;"></span>
</pre><pre name="code" class="html" style="font-family: Georgia, 'Times New Roman', Times, serif; line-height: 1.5; white-space: pre-wrap; font-size: 14px; "><span style="color:#1f2426;"></span>
</pre>2.借助定时器编写一个页面跳转
<!DOCTYPE html>
<html>
<head>
<title>浏览器对象</title>
<meta http-equiv="Content-Type" content="text/html; charset=gkb"/>
</head>
<body>
<!--先编写好网页布局-->
<h1>操作成功</h1>
<br>
<p><span id="sec">5</span>秒后回到主页 <a href="window.history()">返回</a></p>
<script type="text/javascript"> <span style="color:#ff0000;"> //加载history列表中前一个浏览的页面</span>
var count = 5;
//获取显示秒数的元素,通过定时器来更改秒数。
function clock(){
count--;
document.getElementById("sec").innerHTML=count;<span style="color:#ff0000;">//根据id的特性选择的是innerHTML</span>
if(count==0){
location.href = "http://www.imooc.com";<span style="color:#ff0000;">//location.href可以返回完整的url</span>
}
}
var sec = setInterval(clock,1000);
<span style="font-family: 'Microsoft YaHei', SimSun, Arial; font-size: 14px; line-height: 22px; background-color: rgb(223, 222, 227); "><span style="color:#ff0000;">//在执行时,从载入页面后每隔指定的时间执行代码。</span></span><pre class="code" style="color: rgb(31, 36, 38); margin-top: 0px; margin-bottom: 0px; padding: 10px; white-space: pre-wrap; word-wrap: break-word; border: 1px solid rgb(221, 221, 221); background-color: rgb(255, 255, 255); font-family: Georgia, 'Times New Roman', Times, serif; line-height: 1.5; border-top-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-bottom-left-radius: 2px; font-size: 14px; ">
//通过window的location和history对象来控制网页的跳转。 </script> </body></html>效果如下:


<span style="color:#1f2426;">
</span>

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: