日期:2014-05-16 浏览次数:20405 次
?
<html>
<head>
<script type="text/javascript" src="test.js"></script>
<script>
function updown(){
var arr=["3","20","30","50","1"]
arr.sort(a);
alert(arr.toString());
arr.reverse();
alert(arr);
function a(x,y){
return -x.localeCompare(y);
}
}
//function chongfu(){
Array.prototype.distinct = function() {
var ret = [];
for (var i = 0; i < this.length; i++) {
for (var j = i+1; j < this.length;) {
if (this[i] === this[j]) {
ret.push(this.splice(j, 1)[0]);
} else {
j++;
}
}
}
return ret;
}
//for test
alert(['a','b','c','d','b','a','e'].distinct())
//}
</script>
</head>
<body>
<div id="clean">
<button id="b" onClick="updown()">button1</button>
</div>
<div id="clean">
<button id="c" onClick="">button2</button>
</div>
</body>
</html>
?经过观察发现,脚本的执行有两种途径.
一种是在加载页面的时候执行.
一种是需要触发某个事件的时候执行.