Javascript html可以工作,但.add不能';T

Javascript html可以工作,但.add不能';T,javascript,jquery,Javascript,Jquery,我的代码: $(document).ready(function() { $(this.body).html("<p>using .html</p>"); // works $(this.body).add("<p>using .add</p>"); // doesn't work });​ $(文档).ready(函数(){ $(this.body.html(“using.html”);//有效 $(this.body).add

我的代码:

$(document).ready(function() {
    $(this.body).html("<p>using .html</p>"); // works
    $(this.body).add("<p>using .add</p>"); // doesn't work
});​
$(文档).ready(函数(){
$(this.body.html(“using.html

”);//有效 $(this.body).add(“使用.add

”)//不起作用 });​


我做错了什么?

你应该使用附加而不是添加

您要使用:

$(this.body).append(using.add

是为了别的什么:

描述:将元素添加到匹配的元素集中

add()不会写入DOM,它会向jQuery对象添加更多元素

var x = $("li") //would create a jQuery object
x.add("span") //would add span tags to that object. 
要写入要追加()或追加()的jQuery对象的内容


添加
说明:
将元素添加到匹配元素集。

html
将替换
此.body
内容。

append
将添加到内容末尾。也许这就是你想要的。

$(this.body).append('使用.append

')

var x = $("li") //would create a jQuery object
x.add("span") //would add span tags to that object. 
x.appendTo("body");