<script>
function csubstr(str,len){
if(str.length>10){
return str.substring(0,len)+"...";
}else{
return str;
}
}
</script>
<div ><script>document.write(csubstr("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",10));</script></div>
注:不是超出DIV宽度 而是设定字符数 超出字符数省略号代替
用css方法:
(<style type="text/css">.text {width:60px; height:22px;line-height:22px; white-space: nowrap;text-overflow:ellipsis; overflow:hidden; word-wrap: break-word;}</style>)
本文介绍如何使用JavaScript函数csubstr实现字符截取,并通过CSS设置文本样式以适应不同长度,特别关注超出字符数时的省略显示。
1141

被折叠的 条评论
为什么被折叠?



