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
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>
&lt ;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

Hot Article

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Replace String Characters in JavaScript Replace String Characters in JavaScript Mar 11, 2025 am 12:07 AM

Replace String Characters in JavaScript

jQuery Check if Date is Valid jQuery Check if Date is Valid Mar 01, 2025 am 08:51 AM

jQuery Check if Date is Valid

jQuery get element padding/margin jQuery get element padding/margin Mar 01, 2025 am 08:53 AM

jQuery get element padding/margin

Top 5 Date Manipulation JS Plugins Top 5 Date Manipulation JS Plugins Feb 28, 2025 am 12:34 AM

Top 5 Date Manipulation JS Plugins

10 Worth Checking Out jQuery Plugins 10 Worth Checking Out jQuery Plugins Mar 01, 2025 am 01:29 AM

10 Worth Checking Out jQuery Plugins

10 jQuery Accordions Tabs 10 jQuery Accordions Tabs Mar 01, 2025 am 01:34 AM

10 jQuery Accordions Tabs

jquery add scrollbar to div jquery add scrollbar to div Mar 01, 2025 am 01:30 AM

jquery add scrollbar to div

10 Ajax/jQuery Autocomplete Tutorials/Plugins 10 Ajax/jQuery Autocomplete Tutorials/Plugins Feb 28, 2025 am 01:03 AM

10 Ajax/jQuery Autocomplete Tutorials/Plugins

See all articles