1. 程式人生 > >javascript之常用事件

javascript之常用事件

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
/*
常用的事件:
    滑鼠點選相關:
        onclick 在使用者用滑鼠左鍵單擊物件時觸發。 
        ondblclick 當用戶雙擊物件時觸發。 
        onmousedown 當用戶用任何滑鼠按鈕單擊物件時觸發。 
        onmouseup 當用戶在滑鼠位於物件之上時釋放滑鼠按鈕時觸發。 

    滑鼠移動相關:
        onmouseout  當用戶將滑鼠指標移出物件邊界時觸發。 
        onmousemove 當用戶將滑鼠劃過物件時觸發。 

    焦點相關的:
        onblur 在物件失去輸入焦點時觸發。 
        onfocus 當物件獲得焦點時觸發。

    其他:
        onchange 當物件或選中區的內容改變時觸發。 
        onload 在瀏覽器完成物件的裝載後立即觸發。 
        onsubmit 當表單將要被提交時觸發。 
*/ function clickTest(){ alert("單擊.."); } function dbClick(){ alert("雙擊.."); } function showTime(){ var timeSpan = document.getElementById("timeSpan"); var date = new Date().toLocaleString(); timeSpan.innerHTML = date.fontcolor(
"red"); } function hideTime(){ var timeSpan = document.getElementById("timeSpan"); timeSpan.innerHTML = ""; } function showInfo(){ var timeSpan = document.getElementById("userName"); timeSpan.innerHTML = "使用者名稱是由6位的英文與數字組成".fontcolor("green"); }
function hideInfo(){ var timeSpan = document.getElementById("userName"); timeSpan.innerHTML = ""; } function change(){ alert("城市改變了.."); } </script> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>無標題文件</title> </head> <body> <input type="button" onclick="clickTest()" value="單擊" /> <input type="button" ondblclick="dbClick()" value="雙擊"/> <span onmousemove="showTime()" onmouseout="hideTime()" >檢視當前系統時間:</span><span id="timeSpan"></span> 使用者名稱<input type="text" onfocus="showInfo()" onblur="hideInfo()" /> <span id="userName"></span> <select onchange="change()" > <option>廣州</option> <option>深圳</option> <option>上海</option> </select> </body> </html>