淺談 javascript 事件處理
事件處理
一、事件源:任何一個HTML元素(節(jié)點(diǎn)),body、div、button
二、事件:你的操作
鼠標(biāo):
click 單擊
dblick 雙擊
oncontextmenu 文本菜單
<body oncontextmenu="return false">//禁止右鍵的程序
mouseover 放上
mouseout 離開
mousedown 按下
mouseup 抬起
mousemove 鼠標(biāo)移動
鍵盤:
keypress 鍵盤事件
keyup 抬起
keydown 按下
文檔:
load 加載
onload 是頁面加載完成之后觸發(fā)的事件
unload 關(guān)閉
breforeunload關(guān)閉之前
表單:
focus 焦點(diǎn)事件
blur 失去焦點(diǎn)
submit 提交事件
change 改變事件
其它:
scroll 滾動
selectstart 選擇事件
三、事件處理程序
第一種:
格式:<tag on事件="事件處理程序" />
實(shí)例:
<script>
function show(){
var one=document.getElementById("one");
alert(one.innerText);
}
show();
</script>
<body>
<div id="one">
wwwwwwwwwwwwwwwww
</div>
<input type="button" onclick="show()" value="show">
第二種:
直接在javascript里邊對象.on處理程序
<div id="two">
你好,腳本之家http://www.dhdzp.com
</div>
<script>
var one=document.getElementById("two");
one.onclick=function(){
this.style.backgroundColor="red";
}
</script>
第三種:
基本沒什么人用
<script for="事件源ID" event="事件">事件處理程序</script>
<div id="th">
你好,腳本之家http://www.dhdzp.com
</div>
<script for="th" event="onclick">
var one=document.getElementById("th");
one.style.backgroundColor="red";
</script>
小伙伴們是否了解了javascript的事件處理了呢,有疑問就給我留言吧。
相關(guān)文章
javascript學(xué)習(xí)筆記(七) js函數(shù)介紹
javascript學(xué)習(xí)筆記之js函數(shù)介紹,需要的朋友可以參考下2012-06-06
JavaScript基本概念初級講解論壇貼的學(xué)習(xí)記錄
JavaScript基本概念 論壇貼建議大家看下,都是一些js的高級的技巧知識小結(jié)。2009-02-02
Javascript學(xué)習(xí)筆記1 數(shù)據(jù)類型
在Javascript中只有五種簡單類型,分別為null,undefined,boolean,String和Number.一種復(fù)雜類型:object。2010-01-01

