html()方法用于返回或设置被选元素的内容:1、如果未设置参数,则返回被选元素的当前内容,语法“$(selector).html()”;2、如果设置参数,则会覆盖所有匹配元素的内容,语法“$(selector).html(内容值)”。

本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。
jQuery html()方法
html() 方法返回或设置被选元素的内容 (inner HTML)。
返回元素内容
当使用该方法返回一个值时,它会返回第一个匹配元素的内容。
语法
$(selector).html()
示例:
html>
<meta><script>
</script><script>
$(document).ready(function() {
$("button").click(function() {
alert($("p").html());
});
});
</script><p>这是一个 <b>段落</b>。</p>
<button>返回P标签的内容</button>

-
设置元素内容
jQuery 1.12.4下载jQuery 1.12.4是jQuery 1.x系列的最后一个正式稳定版本,由jQuery团队于2016年发布。该版本主要面向需要兼容旧版浏览器环境的网站和Web应用,尤其适用于仍需支持Internet Explorer 6、Internet Explorer 7、Internet Explorer 8等老旧浏览器的项目。
当使用该方法设置一个值时,它会覆盖所有匹配元素的内容。
语法
$(selector).html(content)
content:规定被选元素的新内容,可省略。该参数可包含 HTML 标签。
示例:
html>
<meta><script>
</script><script>
$(document).ready(function() {
$("button").click(function() {
$("p").html("Hello <b>world!");
});
});
</script><p>这是一个段落。</p>
<p>这是另一个段落。</p>
<button>修改所有P元素的内容</button>

相关视频教程推荐:jQuery教程(视频)
前端入门到VUE实战笔记:立即使用
在学习笔记中,你将探索 前端 的入门与实战技巧!










