鼠標事件:
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<title></title> | |
<style> | |
div{ | |
width: 200px; | |
height: 200px; | |
border: 1px solid #000000; | |
float: left; | |
margin: 10px 10px; | |
} | |
div p{ | |
background-color: gray; | |
color: white; | |
height: 40px; | |
line-height: 40px; | |
text-align: center; | |
} | |
</style> | |
<script> | |
//聲明 | |
var a=0; | |
var b=0; | |
var c=0; | |
var d=0; | |
var e=0; | |
function myMove(){ | |
a++; | |
var font = document.getElementById("a");//獲取font標籤對象 | |
font.innerHTML=a; | |
} | |
function myOver(){ | |
b++; | |
var font = document.getElementById("b");//獲取font標籤對象 | |
font.innerHTML=b; | |
} | |
function myOut(){ | |
c++; | |
var font = document.getElementById("c");//獲取font標籤對象 | |
font.innerHTML=c; | |
} | |
function myEnter(){ | |
d++; | |
var font = document.getElementById("d");//獲取font標籤對象 | |
font.innerHTML=d; | |
} | |
function myLeave(){ | |
e++; | |
var font = document.getElementById("e");//獲取font標籤對象 | |
font.innerHTML=e; | |
} | |
</script> | |
</head> | |
<body> | |
<!--<script> | |
document.write("<h1>這是一個標題!</h1>"); | |
document.write('"<h1>這也是一個標題!</h1>"'); | |
document.write("<br />"); | |
document.write("''"); | |
</script>--> | |
<!--<button type="button" οnclick="alert('歡迎')">點我</button>--> | |
<!--<h1>我的JAVA教程</h1> | |
<p id="demo"> | |
王源 | |
</p> | |
<script> | |
function myFunction(){ | |
x=document.getElementById("demo"); | |
x.innerHTML="TFBOYS"; | |
} | |
</script> | |
<button type="button" οnclick="myFunction()">點我</button>--> | |
<!--<script> | |
function changeImage(){ | |
element=document.getElementById('myimage') | |
if(element.src.match("bulbon")) | |
{ | |
element.src="img/2841967bcdcac1bf9e2351b2c8f842f1_pic_bulboff.gif"; | |
} | |
else{ | |
element.src="img/814acbafe5263706f0af6e1ce1b77ae4_pic_bulbon.gif"; | |
} | |
} | |
</script> | |
<img id="myimage" οnclick="changeImage()" | |
src="img/2841967bcdcac1bf9e2351b2c8f842f1_pic_bulboff.gif" width="50px" />--> | |
<div onmousemove="myMove()"> | |
<font id="a">0</font> | |
<p>鼠標移動事件onmousemove</p> | |
</div> | |
<div onmouseover="myOver()"> | |
<font id="b">0</font> | |
<p>鼠標移入事件onmouseover</p> | |
</div> | |
<div onmouseout="myOut()"> | |
<font id="c">0</font> | |
<p>鼠標移出事件onmouseout</p> | |
</div> | |
<div onmouseenter="myEnter()"> | |
<font id="d">0</font> | |
<p>鼠標移入事件onmouseenter</p> | |
</div> | |
<div onmouseleave="myLeave()"> | |
<font id="e">0</font> | |
<p>鼠標移出事件onmouseleave</p> | |
</div> | |
</body> | |
</html> | |