jQuery的each终止或跳过示例代码


涉及迭代,不可避免需要有非正常终止,或强制跳过的情况。在jQuery的each函数中,存在以下关系:
continue :return true;
break :return false;
直接return也会跳出jQuery。

设置下拉列表选中,并终止迭代
复制代码 代码如下:

$("#area option").each(function(){
if($(this).text()==addrTmp[2]){
$(this).attr("selected", "selected");//
return false;
}
});

« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3