HTML long text intercepts the same two methods that contain HTML code _javascript tips

Source: Internet
Author: User
method One: Use CSS to truncate strings: Ie,firefox,opera, Safari compatible
Copy Code code 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" > arbitrary length text </span>

method Two: Use JS intercept
Copy Code code 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> I am code: $.fn.substr = function (l,c) {$ (this). each (function (I,item) </td>
<td> The following two ways can be resolved textarea row height automatic adaptation class capacity </td>
<td> the following two ways to resolve textarea line </td>
</tr>
</table>
</BODY> </HTML>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.