javascript - What is the reason for the infinite loop caused by onblur+alert+focus?
PHPz
PHPz 2017-05-19 10:11:12
0
2
786
<input type="text" id="loginName" onblur="checkLoginName()"/>

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

Already have the focus set, why is this code still in an infinite loop?

PHPz
PHPz

学习是最好的投资!

reply all(2)
phpcn_u1582

What is your "dead loop" phenomenon?

phpcn_u1582

Don’t use alert, it will cause an infinite loop, focus will gain focus, alert will lose focus, and it will continue in an infinite loop. Generally, the processing logic is that the input is marked red, or an error message is appended after the input.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template