如何使用 jQuery 更改元素内的文本?

jqueryweb developmentfront end technology

要使用 jQuery 更改元素内的文本,请使用 text() 方法。

示例

您可以尝试运行以下代码来替换元素内的文本:

<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $('#demo').text('The replaced text.');
});
</script>
</head>
<body>

<div id="demo">
   <p>The initial text</p>
</div>

</body>
</html>

相关文章