HTML长文本截取方法,含有HTML代码同样适用
2013-07-31 16:53
369 查看
方法一:用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 class="subLongText">任意长度文本</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 style="border:1px solid #b3c0f5;" 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>
.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 class="subLongText">任意长度文本</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 style="border:1px solid #b3c0f5;" 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>
相关文章推荐
- HTML长文本截取含有HTML代码同样适用的两种方法
- HTML长文本截取含有HTML代码同样适用的两种方法
- Html长文本超出标记宽度后自动截取实现代码
- C#获取HTML文本的第一张图片与截取内容摘要示例代码
- HTML超出文本多行截取实现原理及代码
- 字符串截取指定长度字节数(Java方法实例,注:同样思路js也适用)
- HTML超出文本多行截取代码
- HTML超出文本多行截取代码
- HTML超出文本多行截取代码
- 字符串截取指定长度字节数(Java方法实例,注:同样思路js也适用)
- HTML超出文本多行截取代码
- 去除文本中的html代码 编辑器适用
- php 将文本区域空格、换行转换成HTML代码后插入数据库的方法
- drupal6中使用drupal_html_to_text方法过滤替换html超文本代码
- 文章生成器,Split方法截取字符串。从硬盘读取文件,和向硬盘存储文件参考代码
- 用text转换html简单代码、截取
- 关于html5与jsp页面同样的html代码展示的页面效果不一样的问题
- 截取带HTML标签的文本并保留文本样式
- 把Word转为简洁html的若干方法 清理 拷贝 word 垃圾 代码 ,word 转 html
- iOS label显示HTML(富文本)代码 (解析)并实现高度自适应