方法一:用CSS截断字符串:IE,FireFox,Opera ,Safari都兼容
代码如下:
.subLongText{
width:150px;
height:24px;
overflow:hidden;
white-space:nowrap;
text-overflow:ellipsis;
text-overflow: ellipsis;/* IE/Safari */
-ms-text-overflow: ellipsis;
-o-text-overflow: ellipsis;/* Opera */
-moz-binding: url("ellipsis.xml#ellipsis");/*FireFox*/
}
任意长度文本
方法二:用js截取
代码如下:
JQUERY 文本截取方法 script>
$.fn.substr = function(length,content){
$(this).each(function(i,item){
var val=$(item).html();
if(!val) return;
if(val.length>length) {
val = val.substring(0,length);
val += content || "..."
$(item).html(val);
}
});
}
function subTdContent(){
$('td').substr(20);
}
script>
我是代码:$.fn.substr = function(l,c){ $(this).each(function(i,item) |
以下两种方式都可以解决textarea行高自动适应类容的高度 |
以下两种方式都可以解决textarea行 |
下载本文