热门关键字:
jquery > jquery教程 > jquery教程 > jQuerytext()方法

jQuerytext()方法

298
作者:管理员
发布时间:2021/1/28 14:26:39
评论数:0
转载请自觉注明原文:http://www.jq-school.com/Show.aspx?id=3560
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
友荐云推荐