如何使用 jQuery 中的 jQuery.text() 方法?
text() 方法獲取所有匹配元素的合併文字內容。這種方法對 XML 和 XHTML 文件都能用。
例項
你可以嘗試執行以下程式碼來學習如何使用 jQuery 中的 jQuery.text() 方法 −
<html>
<head>
<title>jQuery text() method</title>
<script src = "https://ajax.googleapis.com/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