HTML长文本截取含有HTML代码同样适用的两种方法_Javascript教程-查字典教程网
HTML长文本截取含有HTML代码同样适用的两种方法
HTML长文本截取含有HTML代码同样适用的两种方法
发布时间:2016-12-30 来源:查字典编辑
摘要:方法一:用CSS截断字符串:IE,FireFox,Opera,Safari都兼容复制代码代码如下:.subLongText{width:15...

方法一:用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*/

}

<span>任意长度文本</span>

方法二:用js截取

复制代码 代码如下:

<HTML>

<HEAD>

<TITLE>JQUERY 文本截取方法</TITLE>

<meta http-equiv="content-type" content="text/html; charset=UTF-8">

<script type="text/javascript" src="jquery-1.3.2.js"></script>

<script type="text/javascript">

$.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>

</HEAD>

<BODY onload="javascript:subTdContent();">

<table border="1">

<tr>

<td>我是代码:$.fn.substr = function(l,c){ $(this).each(function(i,item)</td>

<td>以下两种方式都可以解决textarea行高自动适应类容的高度</td>

<td>以下两种方式都可以解决textarea行</td>

</tr>

</table>

</BODY> </HTML>

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新Javascript教程学习
    热门Javascript教程学习
    编程开发子分类