如何将变量放在html锚标记中?

时间:2019-01-10 05:12:51

标签: php html

不能正确链接文本。卡在<a>标签上。请帮助。

<?php
$string = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.";
$len=strlen($string);
echo strlen($string) >= 30 ? 
    substr($string, 0, 30) . ' <a href="/*what should I put here*/">[Read more]</a>' : $string;

当点击[阅读更多]时,应在页面上提供全文。

1 个答案:

答案 0 :(得分:-1)

    <!DOCTYPE html>
    <html>
    <head>
    <style>
    #more {display: none;}
    </style>
    </head>
    <body>

    <h2>Read More Read Less Button</h2>
    <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus imperdiet, nulla et dictum interdum, nisi lorem egestas vitae scel<span id="dots">...</span><span id="more">erisque enim ligula venenatis dolor. Maecenas nisl est, ultrices nec congue eget, auctor vitae massa. Fusce luctus vestibulum augue ut aliquet. Nunc sagittis dictum nisi, sed ullamcorper ipsum dignissim ac. In at libero sed nunc venenatis imperdiet sed ornare turpis. Donec vitae dui eget tellus gravida venenatis. Integer fringilla congue eros non fermentum. Sed dapibus pulvinar nibh tempor porta.</span></p>
    <button onclick="myFunction()" id="myBtn">Read more</button>

    <script>
    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";
      }
    }
    </script>

    </body>
    </html>

这是完整的代码