1勤晚、鼠標(biāo)事件
event.x 鼠標(biāo)橫軸
event.y 鼠標(biāo)縱軸
event.keycode 鍵盤值
events.button==0 鼠標(biāo)左鍵
events.button==2 鼠標(biāo)右鍵
events.button==3 鼠標(biāo)左右鍵同時(shí)按下
events.button==4 鼠標(biāo)中鍵
events.button==5 鼠標(biāo)左鍵和中鍵同時(shí)按下
events.button==6 鼠標(biāo)右鍵和中鍵同時(shí)按下
events.button==7 所有三個(gè)鍵都按下
click:當(dāng)用戶單擊鼠標(biāo)按鈕時(shí)觸發(fā)。
input.onclick = function () {
alert('Lee');
};
dblclick:當(dāng)用戶雙擊主鼠標(biāo)按鈕時(shí)觸發(fā)领虹。
input.ondblclick = function () {
alert('Lee');
};
mousedown:當(dāng)用戶按下了鼠標(biāo)還未彈起時(shí)觸發(fā)。
input.onmousedown = function () {
alert('Lee');
};
mouseup:當(dāng)用戶釋放鼠標(biāo)按鈕時(shí)觸發(fā)菌羽。
input.onmouseup = function () {
alert('Lee');
};
mouseover:當(dāng)鼠標(biāo)移到某個(gè)元素上方時(shí)觸發(fā)掠械。
input.onmouseover = function () {
alert('Lee');
};
mouseenter: 在鼠標(biāo)光標(biāo)從元素外部首次移動(dòng)至元素范圍內(nèi)觸發(fā)由缆,不參 與冒泡,而且在光標(biāo)移動(dòng)到后代元素上是不會(huì)觸發(fā)的
input.onmouseenter = function () {
alert('Lee');
};
mouseleave: 在位于元素范圍內(nèi)的鼠標(biāo)光標(biāo)移動(dòng)到元素范圍外之后觸 發(fā)猾蒂,這個(gè)事件不參與冒泡均唉,而且在光標(biāo)移動(dòng)到后代元素上不會(huì)觸發(fā)
input.onmouseenter = function () {
alert('Lee');
};
mouseout:當(dāng)鼠標(biāo)移出某個(gè)元素上方時(shí)觸發(fā)。
input.onmouseout = function () {
alert('Lee');
};
mousemove:當(dāng)鼠標(biāo)指針在元素上移動(dòng)時(shí)觸發(fā)肚菠。
input.onmousemove = function () {
alert('Lee');
};
總結(jié):mouseenter 移入 mouseleave 移出
mouseover 移入 mouseout 移出
區(qū)別就在于(mouseenter 移入 mouseleave 移出 ) 不參與冒泡舔箭,其后代元素上不會(huì)受影響
2、鍵盤事件
keydown:當(dāng)用戶按下鍵盤上任意鍵觸發(fā)蚊逢,如果按住不放层扶,會(huì)重復(fù)觸發(fā)。
onkeydown = function () {
alert('Lee');
};
keyup:當(dāng)用戶釋放鍵盤上的鍵觸發(fā)烙荷。
onkeyup = function () {
alert('Lee');
};
keypress:當(dāng)用戶按下鍵盤上的字符鍵觸發(fā)镜会,如果按住不放,會(huì)重復(fù)觸發(fā)终抽。
onkeypress = function () {
alert('Lee');
};
3戳表、HTML事件
load:當(dāng)頁面完全加載后在window上面觸發(fā),或當(dāng)框架集加載完畢后在框架集上觸發(fā)昼伴。
window.onload = function () {
alert('Lee');
};
unload:當(dāng)頁面完全卸載后在window上面觸發(fā)匾旭,或當(dāng)框架集卸載后在框架集上觸發(fā)。
window.onunload = function () {
alert('Lee');
};
select:當(dāng)用戶選擇文本框(input或textarea)中的一個(gè)或多個(gè)字符觸發(fā)圃郊。
input.onselect = function () {
alert('Lee');
};
change:當(dāng)文本框(input或textarea)內(nèi)容改變且失去焦點(diǎn)后觸發(fā)价涝。
input.onchange = function () {
alert('Lee');
};
input: 輸入
input.oninput = function () {
alert('Lee');
};
focus:當(dāng)頁面或者元素獲得焦點(diǎn)時(shí)在window及相關(guān)元素上面觸發(fā)。
input.onfocus = function () {
alert('Lee');
};
blur:當(dāng)頁面或元素失去焦點(diǎn)時(shí)在window及相關(guān)元素上觸發(fā)持舆。
input.onblur = function () {
alert('Lee');
};
submit:當(dāng)用戶點(diǎn)擊提交按鈕在<form>元素上觸發(fā)色瘩。
form.onsubmit = function () {
alert('Lee');
};
reset:當(dāng)用戶點(diǎn)擊重置按鈕在<form>元素上觸發(fā)。
form.onreset= function () {
alert('Lee');
};
resize:當(dāng)窗口或框架的大小變化時(shí)在window或框架上觸發(fā)逸寓。
window.onresize = function () {
alert('Lee');
};
scroll:當(dāng)用戶滾動(dòng)帶滾動(dòng)條的元素時(shí)觸發(fā)泞遗。
window.onscroll = function () {
alert('Lee');
};