javascript - 在 substring() 文本后显示 div

标签 javascript jquery html

var x= $('div.text').text();
var first15=x.substring(0, 55);
$(".text").html(first15);

if ($(".text").html(first15).length == 55) {
  $('.ShowText').show();

}
.text
{
  width:100px;
  height:100px;
  border:1px solid #000;
  overflow: hidden;
  font-size:10px;
  position:relative;
 }

.ShowText
{
  display:none;
  color:red; 
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="text">.Why do we use it?
It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. The point of using Lorem Ipsum is that it has a more-or-less normal distribution of letters, as opposed to using 'Content here, content here', making it look like readable English. Many desktop publishing packages and web page editors now use Lorem Ipsum as their default model text, and a search for 'lorem ipsum' will uncover many web sites still in their infancy. Various versions have evolved over the years, sometimes by accident, sometimes on purpose (injected humour and the like).
  

</div>
<div class="ShowText">Show more...</div>

你好, 仅当文本有 55 个字符时才可以 show() class="ShowText"吗? 但是当我添加“=”时总是显示“ShowText”

感谢您的回答

最佳答案

就用这个

(first15.length == 55)

因为length

$(".text").html(first15).length  

这里的 length 是 jquery 方法,它将返回该元素中的元素数量,即 1。所以 1 不等于 55 。

关于javascript - 在 substring() 文本后显示 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40895780/

相关文章:

javascript - jQuery- .css() 不适用于输入

jquery - 取消绑定(bind)一组 img 上的悬停事件

javascript - AngularJs 中带有嵌套 ui-view 的体面的 Url

html - 突然我的 Parse 应用程序停止读取一些 Css 文件

html - CSS 图像未正确对齐

javascript - 通过模板字段打开 NavigateUrl 窗口

javascript - this.controller 在 Route 类中未定义

javascript - 输入是否具有 "original value"属性?

javascript - jQuery Datepicker 显示一种格式,发送另一种格式

jquery 通过悬停显示和隐藏 bug,更好的编码吗?