Doesn't return in the js method stop executing? how can it still be executed?

$scope.add = function(){
    $(".showdetailsadd input").each(function () {
        console.log( $(this).parent().find(".colr").length == 1 && $(this).val() == "" )
        if ($(this).parent().find(".colr").length < 1 && $(this).val() == "") {
            nonull = $(this).siblings().find("span").eq(0).text();
            console.log(nonull);
            return false;
        }
    })
    if (nonull) {
        console.log(nonull);
        $scope.XHRmessage_show = nonull + "";
        $scope.message_show_f = true;
        $timeout(function () {
            $scope.message_show_f = false;
        }, 2000)
        return false;
    }
}

Why do you enter the if ($(this). Parent (). Find (".colr"). Length < 1 & & $(this). Val () = = ") condition, already return , but still enter the if (nonull) condition,

?

look forward to the boss"s guidance


use return false; in each () of jquery = normal for use break;
break; it just jumps out of the loop and does not end the method


in the if ($(this). Parent (). Find (".colr"). Length < 1 & & $(this). Val () = = "") condition just jumps out of the $(".showdetailsadd input"). Each () ) loop and has no terminating function, so you jump out of the loop and continue to execute

.
$scope.add = function () {

    $(".showdetailsadd input").each(function () {

        console.log($(this).parent().find(".colr").length == 1 && $(this).val() == "")
        if ($(this).parent().find(".colr").length < 1 && $(this).val() == "") {
            nonull = $(this).siblings().find("span").eq(0).text();
            console.log(nonull);
            return false;            // $(".showdetailsadd input").each() return
        }
    })

    //

    if (nonull) {
        console.log(nonull);
        $scope.XHRmessage_show = nonull + "";
        $scope.message_show_f = true;
        $timeout(function () {
            $scope.message_show_f = false;
        }, 2000)
        return false;
    }

}

Brother, the return in a function can only end the current function, which in this case is

.
function () {
        console.log( $(this).parent().find(".colr").length == 1 && $(this).val() == "" )
        if ($(this).parent().find(".colr").length < 1 && $(this).val() == "") {
            nonull = $(this).siblings().find("span").eq(0).text();
            console.log(nonull);
            return false;
        }
    }
    

I suggest you take a look at JS's book. I don't know enough about the language JS.


return jumps out of the current function. If you take a closer look at the each method, you can see that only one of the callback functions of each pops up, not the each method itself.


when you change each to every and then you want to stop return false

Menu