下面的小提琴演示了这个问题:
http://jsfiddle.net/inconduit/2z6Xa/
这是使用jquery.dotdotdot插件来截断带有省略号的文本。
当有一个像a_really_long_filename_with_no_spaces_at_all.txt这样的单词溢出div时,这个插件不会截断它。有没有办法做到这一点呢?
html:
<div id="wrapper">this_does_not_truncate_because_there_are_no_spaces</div>
<br><br>
<div id="wrapper2">this one has spaces and is truncated properly</div>脚本:
$("#wrapper").dotdotdot({wrap: 'letter'});
$("#wrapper2").dotdotdot({wrap: 'letter'});css:
#wrapper {
width: 100px;
height: 20px;
border: 1px solid red;
}
#wrapper2 {
width: 100px;
height: 20px;
border: 1px solid red;
}发布于 2012-11-10 08:44:44
你真的需要一个插件来做这件事吗?你试过使用CSS text-overflow:ellipsis吗?除了IE 5.5或更低版本或FF 6或更低版本等非常老的浏览器之外,其他所有浏览器都支持它。
有关text-overflow的更多信息,请访问:https://developer.mozilla.org/en-US/docs/CSS/text-overflow
演示页面:http://davidwalsh.name/demo/css-ellipsis.php
https://stackoverflow.com/questions/13318038
复制相似问题