亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

jquery如何把參數列嚴格轉換成數組實現思路

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

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

復制代碼 代碼如下:

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

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

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

總結:當參數個數小于2時,要嚴格保證參數列為數組,嚴格每個都執(zhí)行each操作,則需要對參數列長度是否大于2進行分別對待。

相關文章

最新評論