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.