jquery jumps out of the loop $().each

The loop function of jquery is each()

End jumping out of the loop: return false, equivalent to break;

End this cycle and enter the next cycle: return true, which is equivalent to continue.

Example (1)

function MyEach(obj, text) {
    var val = "";
    
    $("#option").each(function(){
        if($(this.text() == text)) {
            val = $(this).val();
            return false;
        }
    });
    return val;
}

Example (2)

var flag = true;

$('input[type="file"][name="fileField"]').each(function(){
    if($(this).val() != "") {
        debugger;
        
        $.messager.alert('提示:',"请先上传附件","info"); 
        flag = false;
        return false;
    }
});

if(!flag)
    return;

 

 

Guess you like

Origin blog.csdn.net/johnt25/article/details/86174230