jQuerytext()方法用于获取选定元素(包括其后代)的组合文本内容,或设置选定元素的文本内容。
使用text()方法获取内容
下面的示例将向您展示如何获取段落的文本内容:
例试试这个代码»
<script>
$(document).ready(function(){
// Get combined text contents of all paragraphs
$(".btn-one").click(function(){
var str = $("p").text();
alert(str);
});
// Get text contents of the first paragraph
$(".btn-two").click(function(){
var str = $("p:first").text();
alert(str);
});
});
</script>
如果您觉得本文的内容对您的学习有所帮助:
关键字:
jQuery