在jquery中,可以利用append()方法增加列,該方法用于在被選元素的結(jié)尾插入指定內(nèi)容,并將括號(hào)內(nèi)的參數(shù)設(shè)置為td單元格即可,語(yǔ)法為“tr元素對(duì)象.append(td單元格代碼)”。
本教程操作環(huán)境:windows10系統(tǒng)、jquery3.2.1版本、Dell G3電腦。
jquery怎么增加列
append() 方法在被選元素的結(jié)尾(仍然在內(nèi)部)插入指定內(nèi)容。
語(yǔ)法
$(selector).append(content)
content 必需。規(guī)定要插入的內(nèi)容(可包含 HTML 標(biāo)簽)。
使用函數(shù)在指定元素的結(jié)尾插入內(nèi)容。
$(selector).append(function(index,html))
function(index,html)必需。規(guī)定返回待插入內(nèi)容的函數(shù)。
示例如下:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>123</title> <script src="js/jquery.min.js"></script> </head> <body> <script> function addCol() { $col = $("<td>增加的列</td>"); $("tr").append($col); } </script> <table border="1"> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td>January</td> <td>$100</td> </tr> <tr> <td>January</td> <td>$100</td> </tr> <tr> <td>January</td> <td>$100</td> </tr> </table> <input id="Button1" type="button" onclick="addCol()" value="增加列" /> </body> </html>
輸出結(jié)果:
相關(guān)視頻教程推薦:jQuery視頻教程