JavaScript的事件_鍵盤事件的處理函數與HTML事件的處理函數

來源:互聯網
上載者:User

標籤:

一、鍵盤事件的處理函數

  1、keydown:當使用者按下鍵盤上任意鍵觸發,如果按住不放,會重複觸發。

<script type="text/javascript">    window.onload = function(){        onkeydown = function () {//不需要對象調用            alert(‘Lee‘);        };    }</script></head><body>    <input type="button" value="按鈕" /> </body>

 

  2、keypress:當使用者按下鍵盤上的字元鍵觸發,如果按住不放,會重複觸發。

<script type="text/javascript">    window.onload = function(){        onkeypress = function () {            alert(‘Lee‘);        };    } </script></head><body>    <input type="button" value="按鈕" /> </body>

 

  3、keyup:當使用者按了鍵盤上的任意鍵釋放鍵盤上的鍵時會觸發。

<script type="text/javascript">    window.onload = function(){        onkeyup = function () {            alert(‘Lee‘);        };    }</script></head><body>    <input type="button" value="按鈕" /> </body>

 

 

 

 

 

 

二、HTML事件的處理函數

   1.load:當頁面完全載入後在 window 上面自動觸發,或當框架組載入完畢後在框架組上觸發。

<script type="text/javascript">    window.onload = function(){         alert(‘Lee‘);    }</script></head><body>    <input type="button" value="按鈕" /> </body>

 

  2.unload:當頁面完全卸載後(關閉沒有,重新整理的時候會有)在 window 上面自動觸發,或當框架組卸載後在框架組上觸發。

<script type="text/javascript">    window.onunload = function(){        alert(‘Lee‘);    }</script></head><body>    <input type="button" value="按鈕" /> </body>

 

  3.select:當使用者選中文字框(input 或 textarea)中的一個或多個字元並鬆開後觸發。

<script type="text/javascript">    window.onload = function(){        var input = document.getElementsByTagName("input")[0];        input.onselect=function(){            alert(‘Lee‘);        };    };</script></head><body>    <input type="text" value="按鈕" /> </body>

 

  4.change:當文字框(input 或 textarea)內容改變且失去焦點後觸發

<script type="text/javascript">    window.onload = function(){        var input = document.getElementsByTagName("input")[0];        input.onchange=function(){            alert(‘Lee‘);        };    };</script></head><body>    <input type="text" value="按鈕" /> </body>

 

  5.focus:當頁面或者元素獲得焦點時在 window 及相關元素上面觸發

<script type="text/javascript">    window.onload = function(){        var input = document.getElementsByTagName("input")[0];        input.onfocus=function(){            alert(‘Lee‘);        };    };</script></head><body>    <input type="text" value="按鈕" /> </body>

 

  6.blur:當頁面或元素失去焦點時在 window 及相關元素上觸發。

<script type="text/javascript">    window.onload = function(){        var input = document.getElementsByTagName("input")[0];        input.onblur=function(){            alert(‘Lee‘);        };    };</script></head><body>    <input type="text" value="按鈕" /> </body>

 

  7.submit:當使用者點擊提交按鈕在<form>元素上觸發。

<script type="text/javascript">    window.onload = function(){        var form = document.getElementsByTagName("form")[0];        form.onsubmit=function(){            alert(‘Lee‘);        };    };</script></head><body><form>    <input type="submit" value="按鈕" /> </form></body>

 

    8.reset:當使用者點擊重設按鈕在<form>元素上觸發。

<script type="text/javascript">    window.onload = function(){        var form = document.getElementsByTagName("form")[0];        form.onreset=function(){            alert(‘Lee‘);        };    };</script></head><body><form>    <input type="reset" value="按鈕" /> </form></body>

 

  9.resize:當視窗或架構的大小變化時在 window 或架構上觸發(Firefox會執行兩次)。

<script type="text/javascript">    window.onresize = function(){            alert(‘Lee‘);    };</script>

 

  10.scroll:當使用者滾動帶捲軸的元素時觸發(有些瀏覽器重新整理的時候捲軸會動那麼該事件也會執行)。

<script type="text/javascript">    window.onscroll = function(){            alert(‘Lee‘);    };</script></head><body><p>jkdasjfkasfja></p><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><p>jkdasjfkasfja></p></body>

 

JavaScript的事件_鍵盤事件的處理函數與HTML事件的處理函數

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.