jQuery implements article collapse and expansion functions

jQuery implements article collapse and expansion functions

This article example shares the specific code of jQuery to realize the article collapse and expansion functions for your reference. The specific content is as follows

Without further ado, let's get straight to the code

<!DOCTYPE html>
<html lang="en">
 <head>
  <meta charset="UTF-8">
  <title>Article</title>
 </head>
 <body>
  <div>
   <p>Article collapse and expansion function</p>
   <div class="item">
    <div>
     <div style="color: #409EFF;">Exceeds word limit</div>
     <span class="article">
      MQTT is a lightweight, proxy-based publish/subscribe message transmission protocol designed to be open, simple, lightweight, and easy to implement.
      These features make it suitable for use in constrained environments. Networks are expensive, have low bandwidth, and are unreliable.
      Running on embedded devices with limited processor and memory resources. The features of this agreement are:
      Use the publish/subscribe messaging model to provide one-to-many message publishing and decouple applications.
      Message transmission with payload content shielded.
      Provides network connectivity using TCP/IP.
     </span>
     <span class="see" style="color: #409EFF;"></span>
    </div>
   </div>
   <br />
   <div class="item">
    <div>
     <div style="color: #409EFF;">Does not exceed the word count</div>
     <span class="article">ABCDEFGHIJKLNMOPQRSTUVWXYZ</span>
     <span class="see" style="color: #409EFF;"></span>
    </div>
   </div>
   <br />
   <div class="item">
    <div>
     <div style="color: #409EFF;">Exceeds word limit</div>
     <span class="article">
      The correctness of MOS directly affects the normal use of the hard disk, mainly referring to the hard disk type.
      Fortunately, current machines all support the "IDE auto detect" function, which can automatically detect the type of hard disk.
      When you connect a new hard disk or replace the hard disk with a new one, you need to use this function to reset the type.
      Of course, some types of motherboards now can automatically identify the type of hard drive.
      When the hard disk type is wrong, sometimes the system cannot be started at all, and sometimes it can be started but read and write errors will occur.
     </span>
     <span class="see" style="color: #409EFF;"></span>
    </div>
   </div>
  </div>
 </body>
 <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
 <script type="text/javascript">
  $(document).ready(function(){
   //Record the current status of the article var onoff = false;
   //Use $().each to traverse and set each article$('.item').each(function() {
    //Use $(this).find() to get the current article DOM
    var article = $(this).find('.article');
    //Get the article content var str = article.text();
    //Use $(this).find() to get the expanded and collapsed DOM
    var see = $(this).find('.see');
    //When the article has more than 50 words, only the first 50 words are displayed if (str.length > 50) {
     article.text(str.substr(0, 50) + '......');
     see.text('[View]'); //Display the view button at the end of the article}
    //Set button listener see.click(function() {
     if (onoff) {
      article.text(str.substr(0, 50) + '......');
      see.text('[View]');
     } else {
      article.text(str);
      see.text('[收起]');
     }
     onoff = !onoff
    });
   });
  });
 </script>
</html> 

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Example of page detail expansion and collapse function implemented by jQuery

<<:  How to configure Bash environment variables in Linux

>>:  Using jQuery to implement the carousel effect

Recommend

Detailed explanation of mysql filtering replication ideas

Table of contents mysql filtered replication Impl...

JavaScript to achieve elastic navigation effect

This article shares the specific code for JavaScr...

Analysis of the process of building a LAN server based on http.server

I don’t know if you have ever encountered such a ...

Detailed explanation of the use of the <meta> tag in HTML

In the web pages we make, if we want more people ...

JS cross-domain solution react configuration reverse proxy

Cross-domain solutions jsonp (simulate get) CORS ...

How to import and export Cookies and Favorites in FireFox

FireFox is a commonly used browser with many exte...

Dealing with the problem of notes details turning gray on web pages

1. In IE, if relative positioning is used, that is...

Web page HTML code: production of scrolling text

In this section, the author describes the special...

Oracle deployment tutorial in Linux environment

1. Environment and related software Virtual Machi...

JavaScript pre-analysis, object details

Table of contents 1. Pre-analysis 1. Variable pre...

HTML page adaptive width table

In the pages of WEB applications, tables are ofte...

TABLE tags (TAGS) detailed introduction

Basic syntax of the table <table>...</tab...

Solution to the problem that docker logs cannot be retrieved

When checking the service daily, when I went to l...

Teach you 10 ways to center horizontally and vertically in CSS (summary)

A must-have for interviews, you will definitely u...

Learn v-model and its modifiers in one article

Table of contents Preface Modifiers of v-model: l...