How does jquery strictly convert parameter columns into arrays?

Source: Internet
Author: User

If the column of a parameter has only one parameter, the each operation fails. See the following example.
Java code:
<! DOCTYPE html>
<Html>
<Head>
<Style>
P {margin: 8px; font-size: 16px ;}
. Selected {color: red ;}
. Highlight {background: yellow ;}
</Style>
<Script src = "http://code.jquery.com/jquery-latest.js"> </script>
</Head>
<Body>
Hello
 
And
 
Goodbye
 
The script and style are used together to modify the style in the script.
<Script>
Var pp = 3;
Var a = [pp];
Alert ();
$. Each (pp, function (I, n ){
Alert (I );
});
</Script>
 
</Body>
</Html>

The result is that the first time alert is 3, and the second time there is no alert, it means pp is not an array, dom, jason, etc.
How can we ensure that pp is strictly an array? var a = [pp] is simple. In this case, replace the pp in each with a, and the result is 3, 0, which is correct. Note that the brackets convert pp to an array.
Java code:
<! DOCTYPE html>
<Html>
<Head>
<Style>
P {margin: 8px; font-size: 16px ;}
. Selected {color: red ;}
. Highlight {background: yellow ;}
</Style>
<Script src = "http://code.jquery.com/jquery-latest.js"> </script>
</Head>
<Body>
Hello
And
Goodbye
 
The script and style are used together to modify the style in the script.
<Script>
Var pp = 3;
Var a = [pp];
Alert ();
$. Each (a, function (I, n ){
Alert (I );
});
</Script>
 
</Body>
</Html>
Summary: when the number of parameters is less than 2, you must strictly ensure that the parameter columns are arrays, and strictly perform the each operation for each parameter column. whether the length of the parameter column is greater than 2 must be treated separately.
 

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.