JQuery learning-Control List width

Source: Internet
Author: User
First, let's look at a normal list that has not been modified. A list like this occupies a lot of space on the page, and the length of the list item is uneven. Other parts of the page layout must be arranged according to the list width, and cannot be flexibly laid out. JQuery controls the width of the list in two ways. Method 1... SyntaxHighlighter. all ();

First look at a normal list that has not been modified

 
A list like this occupies a lot of space on the page, and the length of the list item is uneven. Other parts of the page layout must be arranged according to the list width, and cannot be flexibly laid out.
JQuery controls the width of the list in two ways.
Method 1: extract text content to control the width of the List
Principle: truncate the same length for all list items. In this way, the width of the intercepted list items is the same. This solution is based on the character width, such as Chinese characters. However, if it is an English character, this solution is not satisfactory. This solution uses jQuery's ready (), each (), text (), and Javascript's substr () functions.
1. ready () function-events of document loading completion. After the function is ready, add special effects or dynamic events. Syntax format:
$ (Document). ready (function)
$ (). Ready (function)
$ (Function)
The Function parameter is a required parameter, indicating the Function definition. Define the function to run after the document is loaded.
2. each () function-traverses the jQuery object. This function traverses the jQuery object and executes the function for each matching element.
Each (function) # execute a function using each matching element as the context.
Each (object, function) # traverse objects and Arrays
$ (Selector). each (function (index, element ))
3. text () function-the content of all matching elements. This function can obtain and set the text that is composed of all matching texts. The syntax format is as follows:
Text ([val | function]) # val indicates the text content, and function indicates the function that generates the text.
4. The substr () method extracts the specified number of characters starting with the start subscript from the string. Syntax format:
StringObject. substr (start, length) # start, required. The starting subscript of the substring to be extracted. Length, optional. The number of characters in the substring.
 
Example:

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.