其他分享
首页 > 其他分享> > append/prepend,after/before之间的关系和区别

append/prepend,after/before之间的关系和区别

作者:互联网

虽然都是JQuery中添加元素的快速方法,但是具有本质区别

append/prepend针对元素的内容(元素的内部),因此在使用他们添加元素时,会在元素内容的最后或者最前添加。

after/before仅仅针对元素(元素的外部),他们的添加效果会在元素外部显现,具体自己体会

function addRow(){
var $tr = $("tbody");
var trHtml =
'<tr>'
+ '<td class = "xuhao">' + '</td>' +
'<td>' + '<img src = "./pics/chakan.png" class = "chakan" />' + '</td>' +
'<td>' + '<img src = "./pics/xiugai.png" class = "xiugai" />' + '</td>' +
'<td>' + '<img src = "./pics/shanchu.png" class = "shanchu" />' + '</td>' +
'<td class = "xingming" >' + '</td>' +
'<td class = "zhanghao" >' + '</td>' +
'<td class = "bumen" >' + '</td>' +
'<td class = "xingbie" >' + '</td>' +
'<td class = "paixuhao" >' + '</td>' +
'<td class = "sfjy" >' + '</td>' +
'</tr>';
$tr.append(trHtml);
}

标签:after,元素,tr,prepend,添加,append,before
来源: https://www.cnblogs.com/2213953937abc/p/15780764.html