我正在使用Wordpress建立一个网站。 我做了一个页脚,从我的留言簿中加载了一个条目。它是这样的:
$(".footer-gastenboek").load("http://darylkeep.com/gastenboek/ .gwolle_gb_first");
我想缩短此条目,如下所示:
$(".footer-gastenboek .gb-entry-content").text(function(index, currentText) {
return currentText.substr(0, 50);
});
但没有任何反应。为什么呢?提前谢谢!
这是输出html
<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>
答案 0 :(得分:1)
因为加载是异步的,所以你必须操纵回调函数中的文本
$(".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);
});
});