<head>
<meta charset="UTF-8">
<title>jquery14</title>
<script src="jquery-3.5.1.min.js"></script>
<script>
$(document).ready(function () {
$("#btn1").click(function () {
$("#test1").text(function(i,origText){
return "Old text: " + origText + "New text: Hello world!
(index: " + i +")";
});
});
$("#btn2").click(function () {
$("#test2").html(function (i,origText) {
return "Old html: " + origText+ "New html:Hello <b>world!</b> (index: " + i +")";
});
});
});
</script>
</head>
<body>
<p id="test1">这是<b>粗体</b>文本。</p>
<p id="test2">这是另一段<b>粗体</b>文本。</p>
<button id="btn1">显示旧/新文本</button>
<button id="btn2">显示旧/新 HTML</button>
</body>
</html>
这个放到 一行里面去, 另起一行 不能识别是 字符串了
<head>
<meta charset="UTF-8">
<title>jquery14</title>
<script src="jquery-3.5.1.min.js"></script>
<script>
$(document).ready(function () {
$("#btn1").click(function () {
$("#test1").text(function(i,origText){
return "Old text: " + origText + "New text: Hello world!(index: " + i +")";
});
});
$("#btn2").click(function () {
$("#test2").html(function (i,origText) {
return "Old html: " + origText+ "New html:Hello <b>world!</b> (index: " + i +")";
});
});
});
</script>
</head>
<body>
<p id="test1">这是<b>粗体</b>文本。</p>
<p id="test2">这是另一段<b>粗体</b>文本。</p>
<button id="btn1">显示旧/新文本</button>
<button id="btn2">显示旧/新 HTML</button>
</body>
</html>