mouse down-up
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
#div1{
width: 100px;
height: 100px;
background-color: black;
}
</style>
</head>
<body>
<div id="div1" onmousedown="zoomout()" onmouseup="zoomin()"></div>
</body>
<script type="text/javascript">
function zoomout(){
var div1=document.getElementById("div1");
div1.style.width="200px";
div1.style.height="200px";
div1.style.backgroundColor="yellowgreen";
}
function zoomin(){
var div1=document.getElementById("div1");
div1.style.width="100px";
div1.style.height="100px";
div1.style.backgroundColor="black";
}
</script>
</html>
onclick
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<p id="p1" onclick="fun()">单击事件测试</p>
</body>
<script type="text/javascript">
function fun(){
var p1=document.getElementById("p1");
p1.innerText="我被单杀了!"
p1.style.fontSize="60px";
}
</script>
</html>
ondblclick
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
#div1{
width: 100px;
height: 100px;
background-color: skyblue;
}
</style>
</head>
<body>
<div id="div1" onclick="zoomout()" ondblclick="zoomin()"></div>
</body>
<script type="text/javascript">
function zoomout(){
var div1=document.getElementById("div1");
div1.style.width="200px";
div1.style.height="200px";
div1.style.backgroundColor="red"
}
function zoomin(){
var div1=document.getElementById("div1");
div1.style.width="100px";
div1.style.height="100px";
div1.style.backgroundColor="skyblue";
}
</script>
</html>
onmouse enter-leave
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<style type="text/css">
#div1{
width: 100px;
height: 100px;
background-color: black;
}
</style>
</head>
<body>
<div id="div1" onmouseenter="zoomout()" onmouseleave="zoomin()" onmousedown="zoomon()"></div>
</body>
<script type="text/javascript">
function zoomout(){
var div1=document.getElementById("div1");
div1.style.width="200px";
div1.style.height="200px";
div1.style.backgroundColor="red";
}
function zoomin(){
var div1=document.getElementById("div1");
div1.style.width="100px";
div1.style.height="100px";
div1.style.backgroundColor="skyblue";
}
function zoomon(){
var div1=document.getElementById("div1");
div1.style.width="200px";
div1.style.height="200px";
div1.style.backgroundColor="black";
}
</script>
</html>
数组排序
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
var classScore = [82, 56, 87, 96, 85, 74, 23, 56, 59, 85, 78, 74, 29, 98, 100, 46, 42, 85, 69];
var small = classScore.sort(function(m, n) {
return m - n;
});
alert(small[0]);
alert(small[small.length-1]);
var sum=classScore.reduce(Arr);
function Arr(m,n){
return m+n;
}
var avg = sum/classScore.length;
alert(avg);
var sum1=0;
for(i=0;i<classScore.length;i++){
sum1+=(avg-classScore[i])*(avg-classScore[i])
}
over=sum1/classScore.length;
alert(Math.sqrt(over));
</script>
</body>
</html>