jquery自定義表格樣式
本文實(shí)例講述了jquery自定義表格樣式實(shí)現(xiàn)代碼。分享給大家供大家參考。具體如下:
運(yùn)行效果截圖如下:
上面這張圖有3種狀態(tài),默認(rèn)狀態(tài)(灰白相間),鼠標(biāo)懸浮狀態(tài)(綠色),鼠標(biāo)點(diǎn)擊狀態(tài)(黃色),是如何實(shí)現(xiàn)的吶?
Html代碼如下:
<table> <thead> <tr> <td>編號(hào)</td> <td>姓名</td> <td>年齡</td> <td>操作</td> </tr> </thead> <tbody> <tr> <td>1111</td> <td>1111</td> <td>1111</td> <td><input type="button" value="查看" /><input type="button" value="刪除" /></td> </tr> <tr> <td>2222</td> <td>2222</td> <td>2222</td> <td><input type="button" value="查看" /><input type="button" value="刪除" /></td> </tr> <tr> <td>3333</td> <td>3333</td> <td>3333</td> <td><input type="button" value="查看" /><input type="button" value="刪除" /></td> </tr> <tr> <td>4444</td> <td>4444</td> <td>4444</td> <td><input type="button" value="查看" /><input type="button" value="刪除" /></td> </tr> <tr> <td>5555</td> <td>5555</td> <td>5555</td> <td><input type="button" value="查看" /><input type="button" value="刪除" /></td> </tr> </tbody> </table>
插件實(shí)現(xiàn)代碼如下:
(function () { $.fn.TabStyle = function (options) { //默認(rèn)參數(shù)設(shè)置 var settings = { evenClass: "tab_even", //偶數(shù)行樣式 oddClass: "tab_odd", //奇數(shù)行樣式 hoverClass: "tab_hover", //鼠標(biāo)懸浮樣式 clickClass: "tab_click", //鼠標(biāo)點(diǎn)擊樣式 isClick: true //是否開啟鼠標(biāo)點(diǎn)擊樣式 }; //合并參數(shù) $.extend(settings, options); return this.each(function () { //為奇偶行分別添加樣式 $(" > tbody > tr:even", this).addClass(settings.evenClass); $(" > tbody > tr:odd", this).addClass(settings.oddClass); $(" > tbody > tr", this).each(function (i) { //鼠標(biāo)懸浮樣式 $(this).hover(function () { $(this).addClass(settings.hoverClass); }, function () { $(this).removeClass(settings.hoverClass); }); //鼠標(biāo)點(diǎn)擊樣式 if (settings.isClick) { $(this).bind("click", function () { $(this).addClass(settings.clickClass).siblings("tr").removeClass(settings.clickClass); }); } }); }); } })();
有些時(shí)候我們可能并不需要鼠標(biāo)點(diǎn)擊后的樣式,因此設(shè)置了isClick這個(gè)作為控制開關(guān)。如果不想要點(diǎn)擊樣式,將其設(shè)置為false即可。
DEMO如下:
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>表格樣式(銀光棒)</title> <style type="text/css"> table{ width:700px; border:1px solid green;border-collapse:collapse;} table td{height:40px; text-align:center; width:25%;} .tab_even{ background-color: #DDD;} .tab_odd{ background-color: White;} .tab_hover{ background-color: Green;color:White;} .tab_click{ background-color: Orange;} </style> </head> <body> <table> <thead> <tr> <td>編號(hào)</td> <td>姓名</td> <td>年齡</td> <td>操作</td> </tr> </thead> <tbody> <tr> <td>1111</td> <td>1111</td> <td>1111</td> <td><input type="button" value="查看" /><input type="button" value="刪除" /></td> </tr> <tr> <td>2222</td> <td>2222</td> <td>2222</td> <td><input type="button" value="查看" /><input type="button" value="刪除" /></td> </tr> <tr> <td>3333</td> <td>3333</td> <td>3333</td> <td><input type="button" value="查看" /><input type="button" value="刪除" /></td> </tr> <tr> <td>4444</td> <td>4444</td> <td>4444</td> <td><input type="button" value="查看" /><input type="button" value="刪除" /></td> </tr> <tr> <td>5555</td> <td>5555</td> <td>5555</td> <td><input type="button" value="查看" /><input type="button" value="刪除" /></td> </tr> </tbody> </table> <script src="../Scripts/jquery-1.4.1.min.js" type="text/javascript"></script> <script src="../Scripts/jquery.similar.TabStyle.js" type="text/javascript"></script> <script type="text/javascript"> $("table").TabStyle(); </script> </body> </html>
通過上文詳細(xì)的代碼,大家應(yīng)該會(huì)利用jquery自定義表格樣式了,小編的表格樣式還不夠完美,還需要進(jìn)行改進(jìn),希望大家在完成這個(gè)樣式的基礎(chǔ)上,繼續(xù)創(chuàng)新,做一個(gè)屬于自己的表格。
- jQuery實(shí)現(xiàn)獲取table表格第一列值的方法
- jQuery插件實(shí)現(xiàn)表格隔行變色及鼠標(biāo)滑過高亮顯示效果代碼
- 基于jQuery實(shí)現(xiàn)的無刷新表格分頁實(shí)例
- 基于jQuery實(shí)現(xiàn)點(diǎn)擊最后一行實(shí)現(xiàn)行自增效果的表格
- jQuery實(shí)現(xiàn)的調(diào)整表格行tr上下順序
- jquery調(diào)整表格行tr上下順序?qū)嵗v解
- 基于jquery實(shí)現(xiàn)表格無刷新分頁
- jquery實(shí)現(xiàn)表格隔行換色效果
- jQuery操作表格(table)的常用方法、技巧匯總
- 使用jQuery操作HTML的table表格的實(shí)例解析
相關(guān)文章
基于jquery 的一個(gè)progressbar widge
這個(gè)widget是包含在wijmo 項(xiàng)目中的一個(gè)widget。目前此widget已經(jīng)開源基于mit和gpl雙協(xié)議,目前是beta版,可能存在bug。2010-10-10jquery異常問題Uncaught?TypeError:?$(...).on?is?not?a?funct
這篇文章主要介紹了jquery異常問題Uncaught?TypeError:?$(...).on?is?not?a?function,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-11-11jQuery動(dòng)畫效果相關(guān)方法實(shí)例分析
這篇文章主要介紹了jQuery動(dòng)畫效果相關(guān)方法,結(jié)合實(shí)例形式較為詳細(xì)的分析了jQuery實(shí)現(xiàn)動(dòng)畫效果所用到的常見方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2015-12-12jQuery實(shí)現(xiàn)數(shù)字自動(dòng)增加或者減少的動(dòng)畫效果示例
這篇文章主要介紹了jQuery實(shí)現(xiàn)數(shù)字自動(dòng)增加或者減少的動(dòng)畫效果,涉及jQuery結(jié)合時(shí)間函數(shù)動(dòng)態(tài)設(shè)置元素屬性相關(guān)操作技巧,需要的朋友可以參考下2018-12-12jquery 正整數(shù)數(shù)字校驗(yàn)正則表達(dá)式
本文主要介紹了jquery正整數(shù)數(shù)字校驗(yàn)正則表達(dá)式的方法。具有一定的參考價(jià)值,下面跟著小編一起來看下吧2017-01-01修改jquery里的dialog對(duì)話框插件為框架頁(iframe) 的方法
為什么我不直接用modal form來做呢?所以我就做了個(gè)jquery下面dialog的插件,需要引用原來dialog的文件。2010-09-09使用jQuery的ajax方法向服務(wù)器發(fā)出get和post請(qǐng)求的方法
這篇文章主要介紹了使用jQuery的ajax方法向服務(wù)器發(fā)出get和post請(qǐng)求的方法,需要的朋友可以參考下2017-01-01