Home > Web Front-end > JS Tutorial > body text

How jquery strictly converts parameter columns into arrays implementation ideas_jquery

WBOY
Release: 2016-05-16 17:38:51
Original
1027 people have browsed it

If a parameter column has only one parameter, then each fails, please see the example below
Java code:

Copy code The code is as follows:








Hello
and
Goodbye
Script works together with style to modify the style in script.
<script> <br>var pp=3; <br>var a=[pp]; <br>alert(a); <br>$.each(pp,function(i,n){ <br>alert(i); <br>}); <br></script>



The result is first The first alert is 3, and the second time there is no alert, indicating that pp is not an array, dom, Jason, etc.
How to ensure that pp is strictly an array? It is very simple: var a=[pp]; this sentence will do. Next, we replace pp in each with a, and the result is 3,0, which is correct. Note that the square brackets convert pp into an array.
Java code:
Copy code The code is as follows:








Hello
and
Goodbye
script works together with style to modify the style in script.
<script> <br>var pp=3; <br>var a=[pp]; <br>alert(a); <br>$.each(a,function(i,n){ <br>alert(i); <br>}); <br></script>



Summary: When parameters When the number is less than 2, it is necessary to strictly ensure that the parameter column is an array, and each operation must be strictly performed. If the parameter column length is greater than 2, it needs to be treated separately.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template