如何使用 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