如何去除事件
<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>
数组的排序算法
<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>
演示下载功能
<head>
<meta charset="utf-8">
<title></title>
<link href="css/bootstrap.css" rel="stylesheet" />
<script src="js/bootstrap.js"></script>
</head>
<body>
<div class="progress" role="progressbar" aria-label="Example with label" aria-valuenow="25" aria-valuemin="0" aria-valuemax="100">
<div id="a" class="progress-bar" style="width: 0%">0%</div>
</div>
<script>
var i = 0;
var div = document.getElementById("a");
var aaa = setInterval(function(){
i++;
div.style.width = i + "%";
div.innerText = i +"%";
if (i==100) {
clearInterval(aaa);
}
},10000);
</script>
</body>
广告牌的运动
<head>
<meta charset="utf-8">
<title></title>
<style>
/* 去除浏览器自带的边距 ,否则影响广告牌移动的距离的误差 */
*{
margin: 0;
}
img{
border: 1px solid red;
margin-top: 200px;
height: 100px;
}
</style>
</head>
<body>
<a href="https://baidu.com/"><img src="img/广告.jpg"/></a>
<script>
var img = document.getElementsByTagName("img")[0];
var zb = 0 ; //表示当前图片的纵向坐标 最上面是0 最下面是??
var maxHight = window.innerHeight - 100;//获取浏览器的宽度高度 还要减去图片自身的高度
var fx = 1;//1表示向下 0 表示向上
setInterval(function(){
maxHight = window.innerHeight - 100;
console.log(maxHight);
if(fx == 1){
zb++;
}else{
zb--;
}
img.style.marginTop = zb + "px";
if(zb>=maxHight){
fx = 0;
}
if(zb<=0){
fx = 1;
}
},1);
</script>
</body>