`
metallica_1860
  • 浏览: 32324 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

前台是个什么东西---JavaScript---执行

阅读更多

 

<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>

 经过观察发现,脚本的执行有两种途径.

一种是在加载页面的时候执行.

一种是需要触发某个事件的时候执行.

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics