javascript
js离焦事件_JavaScript中的事件
/*常見的事件:
1. 點擊事件:
1. onclick:單擊事件
2. ondblclick:雙擊事件
2. 焦點事件
1. onblur:失去焦點。
* 一般用于表單驗證
2. onfocus:元素獲得焦點。
3. 加載事件:
1. onload:一張頁面或一幅圖像完成加載。
4. 鼠標(biāo)事件:
1. onmousedown 鼠標(biāo)按鈕被按下。
* 定義方法時,定義一個形參,接受event對象。
* event對象的button屬性可以獲取鼠標(biāo)按鈕鍵被點擊了。
2. onmouseup 鼠標(biāo)按鍵被松開。
3. onmousemove 鼠標(biāo)被移動。
4. onmouseover 鼠標(biāo)移到某元素之上。
5. onmouseout 鼠標(biāo)從某元素移開。
5. 鍵盤事件:
1. onkeydown 某個鍵盤按鍵被按下。
2. onkeyup 某個鍵盤按鍵被松開。
3. onkeypress 某個鍵盤按鍵被按下并松開。
6. 選擇和改變
1. onchange 域的內(nèi)容被改變。
2. onselect 文本被選中。
7. 表單事件:
1. onsubmit 確認(rèn)按鈕被點擊。
* 可以阻止表單的提交
* 方法返回false則表單被阻止提交。
2. onreset 重置按鈕被點擊。*/
//2.加載完成事件 onload
window.οnlοad= function(){/*//1.失去焦點事件
document.getElementById("username").onblur = function(){
alert("失去焦點了...");
}*/
/*//3.綁定鼠標(biāo)移動到元素之上事件
document.getElementById("username").onmouseover = function(){
alert("鼠標(biāo)來了....");
}*/
/*//3.綁定鼠標(biāo)點擊事件
document.getElementById("username").onmousedown = function(event){
// alert("鼠標(biāo)點擊了....");
alert(event.button);
}*/
/*document.getElementById("username").onkeydown = function(event){
// alert("鼠標(biāo)點擊了....");
// alert(event.button);
if(event.keyCode == 13){
alert("提交表單");
}
}*/
/*document.getElementById("username").onchange = function(event){
alert("改變了...")
}
document.getElementById("city").onchange = function(event){
alert("改變了...")
}*/
/*document.getElementById("form").onsubmit = function(){
//校驗用戶名格式是否正確
var flag = false;
return flag;
}*/}functioncheckForm(){return true;
}
--請選擇--
北京
上海
西安
總結(jié)
以上是生活随笔為你收集整理的js离焦事件_JavaScript中的事件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iserdese2接口详解_Xilinx
- 下一篇: 互相引用 spring_巧夺天工,这样理