Javascript 筆記與總結(2-14)事件

來源:互聯網
上載者:User

標籤:

常用事件:

● onclick 元素點擊時

● onfocus 元素獲得焦點時

● onblur 元素失去焦點時

● onmouseover 滑鼠經過時

● onsubmit 表單提交時(<form onsubmit="return func();"></form>)

● onload 頁面載入完畢時

註:onsubmit = "return func()";  func() 函數才能阻攔提交的結果。

 

【例】onload 的缺點:

img.php,用於展示圖片,這裡讓圖片 5 秒之後輸出

<?php$img = imagecreatetruecolor(300, 300); //建立一個300 * 300 px 的黑色方塊sleep(5); //5 秒之後輸出header("content-type:image/png");imagepng($img);

 

test.html,引用圖片,同時使用 onload 事件改變文字效果

<!DOCTYPE html><html lang="en"><head>    <meta charset="UTF-8">    <title>Document</title>    <script>        function t(){            document.getElementById("p").style.fontWeight = "bold";        }    </script></head><body onload="t();">    <img src="img.php" >    <p id="p">定時改變文字</p>                </body></html>      

 

此時訪問 test.html,頁面顯示:

5 秒之後:

結論:onload 事件必須要等頁面內所關聯的 比如 src 引用來的不論是本站還是外站的全部的元素都載入完畢之後,才執行。

 

 

附:sublime (text2 | test3)快速鍵:

① 輸入:

p>input:text

按 tab ,得到:

<p><input type="text" name="" id=""></p>

 

② 輸入:

p*2>input:text

按 tab,得到:

<p><input type="text" name="" id=""></p><p><input type="text" name="" id=""></p>

 

Javascript 筆記與總結(2-14)事件

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.