Files
freeCodeCamp/guide/chinese/miscellaneous/change-text-inside-an-element-using-jquery/index.md
2018-10-16 21:32:40 +05:30

14 lines
681 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Change Text Inside an Element Using jQuery
localeTitle: 使用jQuery更改元素内的文本
---
使用jQuery您可以更改元素的开始和结束标记之间的文本。您甚至可以更改HTML标记。
jQuery有一个名为`.html()`的函数它允许您在元素中添加HTML标记和文本。之前在元素中的任何内容都将完全替换为您使用此功能提供的内容。
以下是如何重写和斜体化标题的文本:
```
$("h3").html("<em>jQuery Funhouse</em>");
```
jQuery也有一个类似的函数`.text()` ,它只改变文本而不添加标签。因此,当使用`.html()`请记住您将编辑整个标记而不仅仅是文本。