<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?
What is your "dead loop" phenomenon?
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.