jQuery 包含不少供改变和操做 HTML 的强大函数。html
$(selector).html(content)
html() 函数改变所匹配的 HTML 元素的内容(innerHTML)。jquery
$("p").html("W3School");
亲自试一试app
$(selector).append(content)
append() 函数向所匹配的 HTML 元素内部追加内容。函数
$(selector).prepend(content)
prepend() 函数向所匹配的 HTML 元素内部预置(Prepend)内容。htm
$("p").append(" W3School");
亲自试一试get
$(selector).after(content)
after() 函数在全部匹配的元素以后插入 HTML 内容。table
$(selector).before(content)
before() 函数在全部匹配的元素以前插入 HTML 内容。class
$("p").after(" W3School.");
亲自试一试select
函数 | 描述 |
---|---|
$(selector).html(content) | 改变被选元素的(内部)HTML |
$(selector).append(content) | 向被选元素的(内部)HTML 追加内容 |
$(selector).prepend(content) | 向被选元素的(内部)HTML “预置”(Prepend)内容 |
$(selector).after(content) | 在被选元素以后添加 HTML |
$(selector).before(content) | 在被选元素以前添加 HTML |