Home
Web Front-end
JS Tutorial
Two methods that are equally applicable to intercepting long HTML text containing HTML code_javascript skills



Two methods that are equally applicable to intercepting long HTML text containing HTML code_javascript skills
May 16, 2016 pm 05:27 PM
html code
Method 1: Use CSS to truncate the string: IE, FireFox, Opera, and Safari are all compatible
.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">Any length text</span>
Method 2: Use js to intercept
<HTML>
<HEAD>
<TITLE>JQUERY text interception method</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>My code: $.fn.substr = function(l,c){ $(this).each(function(i,item)</td>
<td>The following two methods can solve the problem that the textarea row height automatically adapts to the height of the class content</td>
< ;td>The following two ways can solve the textarea row</td>
</tr>
</table>
</BODY> </HTML>
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*/
}
<span class="subLongText">Any length text</span>
Method 2: Use js to intercept
Copy the code The code is as follows:
<HTML>
<HEAD>
<TITLE>JQUERY text interception method</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>My code: $.fn.substr = function(l,c){ $(this).each(function(i,item)</td>
<td>The following two methods can solve the problem that the textarea row height automatically adapts to the height of the class content</td>
< ;td>The following two ways can solve the textarea row</td>
</tr>
</table>
</BODY> </HTML>
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

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
Two Point Museum: Bungle Wasteland Location Guide
4 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Replace String Characters in JavaScript

10 Ajax/jQuery Autocomplete Tutorials/Plugins
