suchen

Heim  >  Fragen und Antworten  >  Hauptteil

javascript - Was ist der Grund für die durch Onblur+Alert+Focus verursachte Endlosschleife?

<input type="text" id="loginName" onblur="checkLoginName()"/>

function checkLoginName() {
        var loginName = $("#loginName").val();
        if (loginName == "") {
            alert("用户名不能为空!");
            $('#loginName').focus();
        }
    }

Der Fokus ist bereits festgelegt. Warum befindet sich dieser Code immer noch in einer Endlosschleife?

PHPzPHPz2829 Tage vor885

Antworte allen(2)Ich werde antworten

  • phpcn_u1582

    phpcn_u15822017-05-19 10:13:12

    你的“死循环”的现象是什么。

    Antwort
    0
  • phpcn_u1582

    phpcn_u15822017-05-19 10:13:12

    不要用alert,会死循环,focus获取焦点,alert会失去焦点,一直死循环,一般处理逻辑都是input标红,或者input后面追加错误提示信息。

    Antwort
    0
  • StornierenAntwort