<i id='7F92W'><tr id='7F92W'><dt id='7F92W'><q id='7F92W'><span id='7F92W'><b id='7F92W'><form id='7F92W'><ins id='7F92W'></ins><ul id='7F92W'></ul><sub id='7F92W'></sub></form><legend id='7F92W'></legend><bdo id='7F92W'><pre id='7F92W'><center id='7F92W'></center></pre></bdo></b><th id='7F92W'></th></span></q></dt></tr></i><div id='7F92W'><tfoot id='7F92W'></tfoot><dl id='7F92W'><fieldset id='7F92W'></fieldset></dl></div>

    <legend id='7F92W'><style id='7F92W'><dir id='7F92W'><q id='7F92W'></q></dir></style></legend>
      <bdo id='7F92W'></bdo><ul id='7F92W'></ul>
      <tfoot id='7F92W'></tfoot>

      <small id='7F92W'></small><noframes id='7F92W'>

      1. 使用 javascript substring() 创建阅读更多链接

        时间:2023-10-13
          <bdo id='2rXwI'></bdo><ul id='2rXwI'></ul>

            • <small id='2rXwI'></small><noframes id='2rXwI'>

                <tbody id='2rXwI'></tbody>
              <legend id='2rXwI'><style id='2rXwI'><dir id='2rXwI'><q id='2rXwI'></q></dir></style></legend>

                <i id='2rXwI'><tr id='2rXwI'><dt id='2rXwI'><q id='2rXwI'><span id='2rXwI'><b id='2rXwI'><form id='2rXwI'><ins id='2rXwI'></ins><ul id='2rXwI'></ul><sub id='2rXwI'></sub></form><legend id='2rXwI'></legend><bdo id='2rXwI'><pre id='2rXwI'><center id='2rXwI'></center></pre></bdo></b><th id='2rXwI'></th></span></q></dt></tr></i><div id='2rXwI'><tfoot id='2rXwI'></tfoot><dl id='2rXwI'><fieldset id='2rXwI'></fieldset></dl></div>
                1. <tfoot id='2rXwI'></tfoot>

                  本文介绍了使用 javascript substring() 创建阅读更多链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在开发一个经典 ASP 页面,它从数据库中提取一些内容并在前 100 个字符之后创建一个阅读更多链接,如下所示;

                  I'm developing a Classic ASP page that pulls some content from a database and creates a Read more link after the first 100 characters as follows;

                  <div class="contentdetail"><%=StripHTML(rspropertyresults.Fields.Item("ContentDetails").Value)%></div>
                  
                  <script type="text/javascript">
                      $(function() {
                  
                          var cutoff = 200;
                          var text = $('div.contentdetail').text();
                          var rest = $('div.contentdetail').text().substring(cutoff);
                          if (text.length > 200) {
                            var period = rest.indexOf('.');
                            var space = rest.indexOf(' ');
                            cutoff += Math.max(Math.min(period, space), 0);
                          }
                  
                          var visibleText = $('div.contentdetail').text().substring(0, cutoff);
                  
                          $('div.contentdetail')
                              .html(visibleText + ('<span>' + rest + '</span>'))
                              .append('<a title="Read More" style="font-weight:bold;display: block; cursor: pointer;">Read More&hellip;</a>')
                              .click(function() {
                                  $(this).find('span').toggle();
                                  $(this).find('a:last').hide();
                              });
                  
                          $('div.contentdetail span').hide();
                      });
                  </script>
                  

                  但是,脚本显然只是在 100 个字符后截断了文本.最好我希望它继续写文本,直到第一个句号或空格,例如.这可以吗?

                  However, the script obviously just cuts the text off after 100 characters. Preferably I would like it to keep on writing text until the first period or space, for example. Is this possible to do?

                  谢谢.

                  推荐答案

                  var cutoff = 100;
                  var text = $('div.contentdetail').text();
                  var rest = text.substring(cutoff);
                  if (text.length > cutoff) {
                    var period = rest.indexOf('.');
                    var space = rest.indexOf(' ');
                    cutoff += Math.max(Math.min(period, space), 0);
                  }
                  // Assign the rest again, because we recalculated the cutoff
                  rest = text.substring(cutoff);
                  var visibleText = $('div.contentdetail').text().substring(0, cutoff);
                  

                  稍微缩短了一点.编辑:修复了一个错误编辑:生活质量改善

                  shortened it a bit. EDIT: Fixed a bug EDIT: QoL improvement

                  这篇关于使用 javascript substring() 创建阅读更多链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:如何在经典 ASP 中返回 JSON 对象 下一篇:经典 ASP 服务器端 JSON 库

                  相关文章

                  最新文章

                2. <small id='x54WU'></small><noframes id='x54WU'>

                  1. <tfoot id='x54WU'></tfoot>

                        <bdo id='x54WU'></bdo><ul id='x54WU'></ul>
                      <legend id='x54WU'><style id='x54WU'><dir id='x54WU'><q id='x54WU'></q></dir></style></legend>
                      <i id='x54WU'><tr id='x54WU'><dt id='x54WU'><q id='x54WU'><span id='x54WU'><b id='x54WU'><form id='x54WU'><ins id='x54WU'></ins><ul id='x54WU'></ul><sub id='x54WU'></sub></form><legend id='x54WU'></legend><bdo id='x54WU'><pre id='x54WU'><center id='x54WU'></center></pre></bdo></b><th id='x54WU'></th></span></q></dt></tr></i><div id='x54WU'><tfoot id='x54WU'></tfoot><dl id='x54WU'><fieldset id='x54WU'></fieldset></dl></div>