我的代码:jQuery的html的作品,但。新增不
$(document).ready(function() {
$(this.body).html("<p>using .html</p>"); // works
$(this.body).add("<p>using .add</p>"); // doesn't work
});
我在做什么错?
我的代码:jQuery的html的作品,但。新增不
$(document).ready(function() {
$(this.body).html("<p>using .html</p>"); // works
$(this.body).add("<p>using .add</p>"); // doesn't work
});
我在做什么错?
您应该使用追加而不是添加。 fiddle
add()不会写入DOM,它会向jQuery对象添加更多元素。
var x = $("li") //would create a jQuery object
x.add("span") //would add span tags to that object.
要写jQuery对象的内容要追加()或appendTo()...
x.appendTo("body");
add
描述:"Add elements to the set of matched elements."
reference
html
将取代this.body
内容。
append
将添加到内容的末尾。也许这就是你想要的。
$(this.body).append('<p>using .append</p>');