我有这段代码应该只显示一行,但是它不只显示第一行,而是显示全部内容。当我单击“显示更多”按钮时,侧面只会向上滚动到顶部。
PHP:
/* Inside a loop */
<?php
$full_text = get_the_content();
$period_pos = strpos($full_text, ".");
$excerpt = substr($full_text, 0, $period_pos+1); // Get the first line, assuming that a line ends with a period.
$rest = substr($full_text, $period_pos+1); // Get the rest of the text ?> <div class="excerpt">
<?php echo $excerpt; ?> </div> <div class="rest">
<?php echo $rest; ?> </div> <div class="show-more-div">
<a href="#" class="show-more">Show more</a> </div>
jQuery:
$(document).ready(function(){
$(".show-more").click(function(){
$(this).parent().prev().slideDown();
});
});