JavaScript-based extra-partially hidden text _ javascript skills

Source: Internet
Author: User
This article mainly introduces more information about text Hiding Based on JavaScript. If you need more information, refer to this article to share with you the function of hiding more than some text. The code is relatively simple, if you are interested, refer to the following code.

The Code is as follows:

 Hide text after exceeding the limit

Prior to the Oscar Awards, dickaprio won the Best Leading Actor Award from the British Film and Television Art Institute (BAFTA) this year. This award is considered a prelude to the Oscar Award. Although he has been nominated for three times and fans have never been unfair to him, dickapio has not yet won an Oscar.

Prior to the Oscar Awards, dickaprio won the Best Leading Actor Award from the British Film and Television Art Institute (BAFTA) this year. This award is considered a prelude to the Oscar Award. Although he has been nominated for three times and fans have never been unfair to him, dickapio has not yet won an Oscar. However, dikaprio has not yet won an Oscar. However, dikaprio has not yet won an Oscar.

Script // obtains elements based on the class name. In this case, the element name must be obtained using the class to control the string degrees of multiple elements (text, text1. function getByClass (oParent, sClass) {if (oParent. getElementsByClassName) {return oParent. getElementsByClassName (sClass);} else {// IE 8 7 6var arr = []; var reg = new RegExp ('\ B' + sClass + '\ B '); var aEle = oParent. getElementsByTagName ('*'); for (var I = 0; I <aEle. length; I ++) {if (reg. test (aEle [I]. className) {arr. push (aEle [I]) ;}} return arr ;}} function testAuto () {var textName = getByClass (document, 'text'); for (var I = 0; I <textName. length; I ++) {var nowLeng = textName [I]. innerHTML. length; if (nowLeng> 85) {var nowWord = textName [I]. innerHTML. substr (0, 85) + '...'; textName [I]. innerHTML = nowWord; }}testauto (); script

The above code is simple to implement the function of hiding more than a part of the text. I hope you will like it.

Related Article

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.