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: