我正在用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>发布于 2016-09-05 21:46:59
这是因为加载是异步的,所以必须在回调函数中操作文本
$(".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);
});
});https://stackoverflow.com/questions/39331913
复制相似问题