Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用下面的点隐藏DIV中的额外内容_Javascript_Jquery_Html_Css_Ajax - Fatal编程技术网

Javascript 用下面的点隐藏DIV中的额外内容

Javascript 用下面的点隐藏DIV中的额外内容,javascript,jquery,html,css,ajax,Javascript,Jquery,Html,Css,Ajax,我需要在点(…)后面隐藏DIV元素的额外文本 我正在使用 <div style="width:200px; height:2em; line-height:2em; overflow:hidden;" id="box"> this is text this is text this is text this is text </div> 这是文本这是文本这是文本这是文本 结果 它隐藏溢出DIV的其余内容 但我想,如果它必须隐藏,那么三个点应该放在末尾,否则就不

我需要在点(…)后面隐藏DIV元素的额外文本

我正在使用

<div style="width:200px; height:2em; line-height:2em; overflow:hidden;" id="box">
 this is text this is text this is text this is text
</div>

这是文本这是文本这是文本这是文本
结果
它隐藏溢出DIV的其余内容
但我想,如果它必须隐藏,那么三个点应该放在末尾,否则就不会

输出需求

这是文本这是文本这是te…

你要找的是省略号

以下是其使用方法的示例:


你要找的是省略号

以下是其使用方法的示例:


您可以使用简单的javascript,尤其是在使用jQuery时:

jQuery('#box').html(jQuery('#box').html().substr(0,30) + '...');

这将显示前30个字符和3个点

您可以使用简单的javascript,尤其是在使用jQuery时:

jQuery('#box').html(jQuery('#box').html().substr(0,30) + '...');

这将显示前30个字符和3个点

这里有一个可能的解决方案,使用
文本溢出:省略号


下面是一个可能的解决方案,使用
文本溢出:省略号


这很好,但是如果内容长度小于30怎么办?在这种情况下,它会显示点吗?你可以在它周围添加一个if语句,检查长度是否正确,但是如果内容长度小于30怎么办?在这种情况下,它会显示点吗?你总是可以在它周围添加一个if语句来检查长度