比如一个div里的p标签。P标签内文字如果超出我想要的宽度 让它以...形式展示
3 回答
已采纳
echo_kinchao
TA贡献600条经验 获得超86个赞
$(document).ready(function(){
//限制字符个数
$(".class").each(function(){
var maxwidth=23;
if($(this).text().length>maxwidth){
$(this).text($(this).text().substring(0,maxwidth));
$(this).html($(this).html()+'...');
}
});
});
荼酒
TA贡献133条经验 获得超96个赞
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
div{
width: 8em;
overflow:hidden;
white-space:nowrap;
text-overflow:ellipsis;
}
</style>
</head>
<body>
<div>
this is a demo!
</div>
</body>
</html>添加回答
举报
0/150
提交
取消
