用dom1來實現,根據游標移動自動給表單加上背景色,游標移開自動去除背景色

來源:互聯網
上載者:User

標籤:mouse   span   圖片   列表   col   實現   class   doctype   返回   

 1 <!DOCTYPE html> 2 <html lang="en"> 3 <head> 4     <meta charset="UTF-8"> 5     <title>Title</title> 6 </head> 7 <body> 8 <table border="1" width="480px" > 9 <tr><td>1</td><td>2</td><td>3</td></tr>10 <tr><td>1</td><td>2</td><td>3</td></tr>11 <tr><td>1</td><td>2</td><td>3</td></tr>12 </table>13 <script>14     var myTrs = document.getElementsByTagName(‘tr‘)//傳回值是一個列表,15     var len = myTrs.length;16     for(i=0;i<len;i++){//迴圈這個列表得到每一tr並給他添加屬性17         myTrs[i].onmouseover = function () {//onmouseover= function ()是游標移動到某個位置就執行這個匿名函數18             this.style.backgroundColor = ‘red‘//這是this的意思是誰調用的這個函數,this就代指哪個標籤19         };20 21 22 23         myTrs[i].onmouseout = function () {//onmouseout = function ()是游標移動到某個位置就執行這個匿名函數24             this.style.backgroundColor=‘‘25         };26 27    }28 </script>29 </body>30 </html>

效果如:

 

用dom1來實現,根據游標移動自動給表單加上背景色,游標移開自動去除背景色

相關文章

聯繫我們

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