取行數(shù),分奇偶,每當(dāng)是奇數(shù)時(shí),這一行加淡灰色樣式。還有就是事先定義好兩種樣式的行,通過判斷迭代器的奇偶來(lái)顯示對(duì)應(yīng)樣式的行。
成都創(chuàng)新互聯(lián)公司專業(yè)為企業(yè)提供龍?zhí)毒W(wǎng)站建設(shè)、龍?zhí)蹲鼍W(wǎng)站、龍?zhí)毒W(wǎng)站設(shè)計(jì)、龍?zhí)毒W(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、龍?zhí)镀髽I(yè)網(wǎng)站模板建站服務(wù),10余年龍?zhí)蹲鼍W(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
!DOCTYPE?HTML
html
head
meta?charset="UTF-8"?/
titleMODEL?PAGE/title
style?type="text/css"
TABLE?{
border-collapse:?collapse;
border:?1px?solid?black;
}
TD?{
border:?1px?solid?black;
}
/style
script?type="text/javascript"?src="jquery-1.8.0.min.js"/script
script?type="text/javascript"
$?(function?()
{
$?('tr').css?("background-color",?"red");
$?('tr').each?(function?(i,?dom)
{
var?isRowSpan?=?$?(this).is?(function?()
{
return?$?('td[rowspan]',?this).length??0;
});
if?(isRowSpan)
{
var?count?=?$?(this).find?('td[rowspan]').prop?('rowspan');
$?(this).nextAll?('tr:lt('?+?(count?-?1)?+?')').andSelf?().css?("background-color",?"green");
}
});
});
/script
/head
body
table?width="100%"?border="1"
tr
thMonth/th
thSavings/th
thSavings?for?holiday!/th
/tr
tr
tdJanuary/td
td$100/td
td?rowspan="3"$50/td
/tr
tr
tdFebruary/td
td$80/td
/tr
tr
tdFebruary/td
td$60/td
/tr
/table
/body
/html
jQuery 選擇器中,:even可以選擇偶數(shù)行
示例如下
$("ul?li").css("background","blue");
$("ul?li:even").css("background","red");
本文實(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;itb.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編號(hào)/thth姓名/thth年齡/th
/tr
/thead
tbody
tr
td1/tdtd張三/tdtd12/td
/tr
tr
td2/tdtd李四/tdtd22/td
/tr
tr
td3/tdtd王五/tdtd13/td
/tr
tr
td4/tdtd馬六/tdtd14/td
/tr
tr
td5/tdtd伍六七/tdtd17/td
/tr
tr
td6/tdtd梅花十三/tdtd17/td
/tr
/tbody
/table
/body
/html
疑問:為什么this.style.backgroundColor
=
oldColor中的this不能用$("tbody
tr")[i]代替??
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:jquery實(shí)現(xiàn)表格隔行換色效果jQuery插件實(shí)現(xiàn)表格隔行換色且感應(yīng)鼠標(biāo)高亮行變色使用jquery
hover事件實(shí)現(xiàn)表格的隔行換色功能示例基于Jquery的表格隔行換色,移動(dòng)換色,點(diǎn)擊換色插件
jQuery 選擇器中,:even可以選擇偶數(shù)行
示例如下
$("ul?li").css("background","blue");
$("ul?li:even").css("background","red");
新聞標(biāo)題:jquery隔行變色,jquery表格隔行變色
文章出自:http://jinyejixie.com/article28/dsedhcp.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、定制網(wǎng)站、商城網(wǎng)站、做網(wǎng)站、網(wǎng)頁(yè)設(shè)計(jì)公司、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)