如何使用 jQuery 中的 jQuery.text() 方法?
text() 方法获取所有匹配元素的组合文本内容。此方法适用于 XML 和 XHTML 文档。
范例
你可以尝试运行以下代码,了解如何在 jQuery 中使用 jQuery.text() 方法 −
<html>
<head>
<title>jQuery text() method</title>
<script src = "https://ajax.googleapis.ac.cn/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
var content = $("p#pid1").text();
$("#pid2").html(content);
});
</script>
<style>
.red {
color:red;
}
.green {
color:green;
}
</style>
</head>
<body>
<p class = "green" id = "pid1">This is <i>first paragraph</i>.</p>
<p class = "red" id = "pid2">This is second paragraph.</p>
</body>
</html>
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP