前端技术
js中each方法跳出循环
标签: js

js中常用each来遍历dom元素,但是each总没有break,需要使用return false来跳出循环,其他return 0,return true,return 1都相当于continue,是结束当前循环。如下:

$('#freight option').each(function(){ 
	console.log('info.freight'+info.freight);
	if(info.freight==this.value){
		console.log('info.freight=='+info.freight);
		console.log($(this).is(':hidden'));
		if($(this).is(':hidden')){
			
		}else{
			$('#freight_lock').prop('checked','checked');
			$('#freight').val(info.freight); 
		} 
		return false;
	}
});  		


 
首页| linux系统和软件使用| PHP后端| 前端技术| 生活杂记| 小程序| 软件和工具使用| 框架使用| 自制网站|