改變方法:1、獲取需要跨行的單元格元素,語(yǔ)法“$("指定單元格元素")”,會(huì)返回一個(gè)包含指定元素的jquery對(duì)象;2、用attr()給指定元素對(duì)象修改rowspan屬性,語(yǔ)法“指定元素對(duì)象.attr("rowspan","行數(shù)值")”。
本教程操作環(huán)境:windows7系統(tǒng)、jquery1.10.2版本、Dell G3電腦。
rowspan,是HTML語(yǔ)言中的一個(gè)元素屬性,用于指定單元格應(yīng)跨越的行數(shù)。
也就是說(shuō),如果一行跨越兩行,則意味著它將占用該表中兩行的空間。它允許單個(gè)表格單元格跨越多個(gè)單元格或行的高度。rowspan屬性與Excel中的電子表格的“合并單元格”有相同的功能。
rowspan屬性可以與HTML表中的<td>和<th>元素一起使用。
-
rowspan屬性與<td>標(biāo)簽一起使用時(shí),rowspan屬性決定了它應(yīng)跨越的標(biāo)準(zhǔn)單元格數(shù)。
-
當(dāng)rowspan屬性與<th>標(biāo)簽一起使用時(shí),rowspan屬性確定它應(yīng)該跨越的標(biāo)題單元格的數(shù)量。
jquery怎么改變r(jià)owspan值
1、獲取需要跨行的單元格元素(td或th)
$("單元格元素")
會(huì)返回包含指定單元格元素的jquery對(duì)象
2、使用attr()修改rowspan屬性
元素對(duì)象.attr("rowspan","行數(shù)值")
示例:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <script src="js/jquery-1.10.2.min.js"></script> <script> $(document).ready(function() { $("button").on("click", function() { $("#zk").attr("rowspan","3") }); }); </script> </head> <body class="ancestors"> <table border="1"> <tr> <th>商品</th> <th>價(jià)格</th> <th>假期折扣價(jià)</th> </tr> <tr> <td>T恤</td> <td>¥100</td> <td id="zk" rowspan="2">¥50</td> </tr> <tr> <td>牛仔褂</td> <td>¥250</td> </tr> <tr> <td>牛仔庫(kù)</td> <td>¥150</td> </tr> </table><br> <button>改變r(jià)owspan值</button> </body> </html>
【推薦學(xué)習(xí):jQuery視頻教程、web前端視頻】