Home > Web Front-end > JS Tutorial > body text

Two methods that are equally applicable to intercepting long HTML text containing HTML code_javascript skills

WBOY
Release: 2016-05-16 17:27:34
Original
1388 people have browsed it
Method 1: Use CSS to truncate the string: IE, FireFox, Opera, and Safari are all compatible
Copy code The code is as follows:

.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*/
}
Any length text

Method 2: Use js to intercept
Copy the code The code is as follows:



JQUERY text interception method


< 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);
}



< table style="border:1px solid #b3c0f5;" border="1">

My code: $.fn.substr = function(l,c){ $(this).each(function(i,item)
The following two methods can solve the problem that the textarea row height automatically adapts to the height of the class content
< ;td>The following two ways can solve the textarea row



Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!