jQuery 文档操作 - html() 方法

https://www.runoob.com/jquery/html-html.html

改变所有 <p> 元素的内容:

$("button").click(function(){ $("p").html("Hello <b>world</b>!"); });

定义和用法

html() 方法设置或返回被选元素的内容(innerHTML)。

当该方法用于返回内容时,则返回第一个匹配元素的内容。

当该方法用于设置内容时,则重写所有匹配元素的内容。

提示:如只需设置或返回被选元素的文本内容,请使用 text() 方法。

语法

返回内容:

$(selector).html()

设置内容:

$(selector).html(content)

使用函数设置内容:

$(selector).html(function(index,currentcontent))
posted @ 2022-10-17 14:16  yinghualeihenmei  阅读(14)  评论(0编辑  收藏  举报