如何设置.load

时间:2016-11-17 14:55:57

标签: jquery

我从另一个页面中提取了一段文本,但是想限制.load事件所带来的字符数量。如何控制从“.paragraph”类中提取的字符数量?

这是我到目前为止所做的:

$("document").ready(function(){   
    // Blog Descriptions
    $( ".blog-description-3" ).load( "/blog.html .blog-post:nth-of-type(3) .blog-content .paragraph");
});

1 个答案:

答案 0 :(得分:1)

您不能限制该方法提取的字符数。但您可以使用substr()

操纵返回的字符串并将其剪切为您的需要
$(".blog-description-3").load("/blog.html .blog-post:nth-of-type(3) .blog-content .paragraph", function() {
    var txt = $(".blog-description-3").text().substr(0, 20);
    $(".blog-description-3").text(txt);
});
相关问题