数组的排序算法
<script>
var a = [1,432,6,234,65,76,876,987];
a.sort(function(a,b){
return b-a; //倒序
})
console.log(a);
a.sort(function(a,b){
return a-b; //正序
})
console.log(a);
a.sort(function(){
return Math.random() - 0.5; //随机排列
})
console.log(a);
</script>
如何去除事件
<body>
<button>按钮</button>
<button>取消按钮</button>
<script>
document.getElementsByTagName("button")[0].onclick = function(){
alert(123);
}
document.getElementsByTagName("button")[1].onclick = function(){
document.getElementsByTagName("button")[0].onclick = null;
}
</script>
</body>