jQuery實(shí)現(xiàn)動態(tài)生成表格并為行綁定單擊變色動作的方法

本文實(shí)例講述了jQuery實(shí)現(xiàn)動態(tài)生成表格并為行綁定單擊變色動作的方法。分享給大家供大家參考,具體如下:

惠水網(wǎng)站建設(shè)公司創(chuàng)新互聯(lián)建站,惠水網(wǎng)站設(shè)計(jì)制作,有大型網(wǎng)站制作公司豐富經(jīng)驗(yàn)。已為惠水近1000家提供企業(yè)網(wǎng)站建設(shè)服務(wù)。企業(yè)網(wǎng)站搭建\外貿(mào)營銷網(wǎng)站建設(shè)要多少錢,請找那個(gè)售后服務(wù)好的惠水做網(wǎng)站的公司定做!

<html>
<head>
<meta charset="utf-8">
<title>jquery表格單擊變色</title>
<script type="text/javascript" src="jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(function(){
/////////////////以下動態(tài)生成10行2列的表格
for(i=1;i<=10;i++)
{
$("#mytable").append("<tr><td>&nbsp;</td><td>&nbsp;</td></tr>"); 
}
/////////////表格生成結(jié)束
/////////////為生成的行添加單擊變色動作
$("#mytable tr").click(function(){
if($(this).hasClass("redcss"))
{
$(this).siblings("tr").removeClass("redcss");
}
else
{
$(this).addClass("redcss");
$(this).siblings("tr").removeClass("redcss");
}
})
})
</script>
<style>
.redcss{
background-color:#900;
}
</style>
</head>
<body>
<table width="200" border="1" id="mytable"></table>
</table>
</body>
</html>

運(yùn)行效果如下:

jQuery實(shí)現(xiàn)動態(tài)生成表格并為行綁定單擊變色動作的方法

更多關(guān)于jQuery相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《jQuery表格(table)操作技巧匯總》、《jQuery切換特效與技巧總結(jié)》、《jQuery擴(kuò)展技巧總結(jié)》、《jQuery常用插件及用法總結(jié)》、《jQuery常見經(jīng)典特效匯總》及《jquery選擇器用法總結(jié)》

希望本文所述對大家jQuery程序設(shè)計(jì)有所幫助。

本文題目:jQuery實(shí)現(xiàn)動態(tài)生成表格并為行綁定單擊變色動作的方法
網(wǎng)站地址:http://muchs.cn/article22/gjgscc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開發(fā)、網(wǎng)站設(shè)計(jì)公司ChatGPT、網(wǎng)站排名、定制網(wǎng)站、服務(wù)器托管

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)

網(wǎng)站建設(shè)網(wǎng)站維護(hù)公司