jQuery實(shí)現(xiàn)表格隔行換色
本文實(shí)例為大家分享了jQuery實(shí)現(xiàn)表格隔行換色的具體代碼,供大家參考,具體內(nèi)容如下
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>使用JQ完成表格隔行換色</title> <script src="js/jquery.min.js"></script> <script> $(function() { $("tbody tr:odd").css("background-color","aquamarine"); $("tbody tr:even").css("background-color","bisque"); var tb = $("tbody tr"); var oldColor; for(var i=0;i<tb.length;i++) { //alert(oldColor); $("tbody tr")[i].onmouseover = function() { oldColor = this.style.backgroundColor; this.style.backgroundColor = "yellow"; } $("tbody tr")[i].onmouseout = function() { this.style.backgroundColor = oldColor; } } }); </script> </head> <body> <table id="tbl" border="1" border-collapse="collapse" align="center" cellspacing="0" cellpadding="5" width="400" height="20"> <thead> <tr> <th>編號</th><th>姓名</th><th>年齡</th> </tr> </thead> <tbody> <tr> <td>1</td><td>張三</td><td>12</td> </tr> <tr> <td>2</td><td>李四</td><td>22</td> </tr> <tr> <td>3</td><td>王五</td><td>13</td> </tr> <tr> <td>4</td><td>馬六</td><td>14</td> </tr> <tr> <td>5</td><td>伍六七</td><td>17</td> </tr> <tr> <td>6</td><td>梅花十三</td><td>17</td> </tr> </tbody> </table> </body> </html>
疑問:為什么this.style.backgroundColor = oldColor中的this不能用$("tbody tr")[i]代替??
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
淺談ajax在jquery中的請求和servlet中的響應(yīng)
下面小編就為大家分享一篇淺談ajax在jquery中的請求和servlet中的響應(yīng),具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-01-01基于jQuery實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊導(dǎo)航菜單水波動畫效果附源碼下載
這篇文章主要介紹了基于jQuery實(shí)現(xiàn)鼠標(biāo)點(diǎn)擊導(dǎo)航菜單水波動畫效果附源碼下載,需要的朋友參考下2016-01-01jquery學(xué)習(xí)總結(jié)(超級詳細(xì))
本文僅針對jquery的部分知識點(diǎn)做總結(jié),更為全面的可以去官網(wǎng)看中文文檔??梢愿鼮樵敿?xì)的了解jquery及其特性。2014-09-09Spring MVC中Ajax實(shí)現(xiàn)二級聯(lián)動的簡單實(shí)例
下面小編就為大家?guī)硪黄猄pring MVC中Ajax實(shí)現(xiàn)二級聯(lián)動的簡單實(shí)例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-07-07jQuery中append、insertBefore、after與insertAfter的簡單用法與注意事項(xiàng)
這篇文章主要為大家介紹了jQuery中append、appendTo、prepend、prependTo、before、insertBefore、after與insertAfter方法注意事項(xiàng),需要的朋友可以參考下2010-12-12jQuery實(shí)現(xiàn)表格顏色交替顯示的方法
這篇文章主要介紹了jQuery實(shí)現(xiàn)表格顏色交替顯示的方法,涉及jQuery操作表格樣式的技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-03-03