歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> jQuery循環中的break和continue

jQuery循環中的break和continue

日期:2017/3/1 10:14:21   编辑:Linux編程
在jQuery中循環頁面中各個控件的操作用的很多,常用的循環操作如下:

// 循環頁面上id為weiguo_開頭的所有div標簽

$("div[id^=weiguo_]").each(function(index){

//獲取div中的內容

var iDValue=$(this).text();

// 如果這次循環符合條件,馬上跳出循環。

if(iDValue==0){
checkMark=false;
blankTextArray.push(idval);
// break----用return false 語法來標識
return false;

}

}

需要注意的地方

在each代碼塊內不能使用break和continue,要實現break和continue的功能的話,要使用如下的方式:
break----用return false;
continue --用return ture;

所以在jquery循環中想返回false或 返回true ,操作需要特別注意,寫的語句可能並不是自己想要的。

Copyright © Linux教程網 All Rights Reserved