首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >加载jQuery () div,然后在该div上使用jQuery

加载jQuery () div,然后在该div上使用jQuery
EN

Stack Overflow用户
提问于 2016-09-05 21:40:43
回答 1查看 23关注 0票数 1

我正在用Wordpress做一个网站。我创建了一个页脚,它加载了我的留言簿中的一个条目。它是这样做的:

代码语言:javascript
复制
$(".footer-gastenboek").load("http://darylkeep.com/gastenboek/ .gwolle_gb_first");

我想缩短此条目,如下所示:

代码语言:javascript
复制
$(".footer-gastenboek .gb-entry-content").text(function(index, currentText) {
    return currentText.substr(0, 50); 
});

但是什么也没发生。但是为什么呢?提前感谢!

这是输出的html

代码语言:javascript
复制
<div class="footer-gastenboek">
    <div class="gb-entry gb-entry_9 gb-entry-count_1 gwolle_gb_uneven gwolle_gb_first admin-entry">
        <div class="gb-author-info">
            <span class="gb-author-name"><i>darylkeep</i></span>
            <span class="gb-datetime">
                <span class="gb-date"> schreef op 5 september 2016</span>:
            </span> 
        </div>
        <div class="gb-entry-content">
            Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est .
        </div>
    </div>
</div>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-09-05 21:46:59

这是因为加载是异步的,所以必须在回调函数中操作文本

代码语言:javascript
复制
$(".footer-gastenboek").load("http://darylkeep.com/gastenboek/ .gwolle_gb_first", function() {
    $(".footer-gastenboek .gb-entry-content").text(function(index, currentText) {
        return currentText.substr(0, 50); 
    });
});
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/39331913

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档