欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

jquery如何把參數(shù)列嚴(yán)格轉(zhuǎn)換成數(shù)組實(shí)現(xiàn)思路

 更新時間:2013年04月01日 15:02:50   作者:  
某參數(shù)的列只有一個參數(shù),那么each是失敗,如何保證pp嚴(yán)格是數(shù)組呢,很簡單var a=[pp];這一句就行了,感興趣的朋友可以參考下哈,希望可以幫助到你

如果某參數(shù)的列只有一個參數(shù),那么each是失敗,請看下面的例子
Java代碼:

復(fù)制代碼 代碼如下:

<!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
script配合style一起實(shí)現(xiàn)在script修改樣式。
<script>
var pp=3;
var a=[pp];
alert(a);
$.each(pp,function(i,n){
alert(i);
});
</script>
</body>
</html>

結(jié)果是第一次alert是3,第二次沒有alert,說明pp不是數(shù)組,dom,jason等。
如何保證pp嚴(yán)格是數(shù)組呢,很簡單var a=[pp];這一句就行了,下面我們把each里面的pp換成a,則結(jié)果是3,0,正確。注意這個中括號把pp轉(zhuǎn)換成了數(shù)組。
Java代碼:
復(fù)制代碼 代碼如下:

<!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
script配合style一起實(shí)現(xiàn)在script修改樣式。
<script>
var pp=3;
var a=[pp];
alert(a);
$.each(a,function(i,n){
alert(i);
});
</script>
</body>
</html>

總結(jié):當(dāng)參數(shù)個數(shù)小于2時,要嚴(yán)格保證參數(shù)列為數(shù)組,嚴(yán)格每個都執(zhí)行each操作,則需要對參數(shù)列長度是否大于2進(jìn)行分別對待。

相關(guān)文章

最新評論