如何在段落中添加ReadMore

时间:2019-02-24 09:40:45

标签: php jquery html css laravel

我有一个用于主页的控制器,该控制器提供import time def prime_number(number1): l=[] for desired_num in range(1,int(number1)+1): if desired_num > 1: for i in range(2,desired_num): if (desired_num % i) == 0: break else: l.append(desired_num) print(l) number2 = int(raw_input ("Enter any number :- ")) print "Prime numbers between 1 and", number2, "are :-" start = time.time() prime_number(number2) print(time.time() - start) var,其中包含该帖子的标题和正文,有时正文中可能有大量文本

$posts

,我想隐藏所有段落文本并添加一个名为ReadMore的按钮,该按钮显示完整的段落 我看到了以下引导示例

return view('posts.index',compact('posts'));
function myFunction() {
  var dots = document.getElementById("dots");
  var moreText = document.getElementById("more");
  var btnText = document.getElementById("myBtn");

  if (dots.style.display === "none") {
    dots.style.display = "inline";
    btnText.innerHTML = "Read more";
    moreText.style.display = "none";
  } else {
    dots.style.display = "none";
    btnText.innerHTML = "Read less";
    moreText.style.display = "inline";
  }
}

在上面的示例文本中,中间有span ID,在这里我不知道如何在<h2>Read More Read Less Button</h2> <p>Lorem ipsum imperdiet, nulla et dictum interdum, nisi lorem egestas vitae scel<span id="dots">...</span><span id="more">erisque enim nibh tempor porta.</span></p> <button onclick="myFunction()" id="myBtn">Read more</button>数据之间添加该span。有什么办法可以制作ReadMore和ShowLess功能? 我目前将数据显示为

$post->body

1 个答案:

答案 0 :(得分:2)

请尝试以下代码:

{{ substr( $post->body, 0, random_int(60, 150)) }}

要获取更多信息,您可以在锚标签中链接单篇文章:

<a href="/post/{{ $post->id }}">Read more </a>