<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div class="div1">
<h2>我是标题1</h2>
</div>
<div class="div2">
<h2>我是标题2</h2>
</div>
<script type="text/javascript" src="../jquery-3.2.1.js"></script>
<script type="text/javascript">
$(function () {
console.log($("div").html());
console.log($("div").text());
$(".div1").text("<p>我是段落</p>");
$(".div2").html("<p>我是段落</p>");
})
</script>
</body>
</html>
上述运行结果: