在满足特定条件时停止JavaScript函数

问题描述 投票:62回答:5

当满足给定条件时,我找不到推荐的方法来停止函数。我应该使用像exitbreak这样的东西吗?

我目前正在使用这个:

if ( x >= 10 ) { return; }  
// other conditions;
javascript function exit breadcrumbs
5个回答
-1
投票

尝试使用return语句。它工作得最好。在满足条件时停止该功能

   `function anything() {
    var get = document.getElementsByClassName("text ").value;
    if (get == null) {
    alert("Please put in your name");
    }
    return;

    var random = Math.floor(Math.random() * 100) + 1;
    console.log(random);
    }`
© www.soinside.com 2019 - 2024. All rights reserved.