유효성 검사가 실패 할 때 동일한 요소에 집중하려고합니다. 여기 내 HTML 코드입니다 :Javascript - 경고 메시지 후 포커스 설정
<input id="potatoes" name="potatoes" value="" type="text" class="tooltip" onblur="Validate('potatoes')" autocomplete='off'>
여기 내 자바 스크립트 코드입니다 :
function Validate(id) {
var errors = {
potatoes : 'enter potatoes',
hamburgers : 'enter'
};
if (document.getElementById(id).value === '') {
if (id in errors) {
alert(errors[id]);
//setTimeout(function(){document.getElementById(id).focus();}, 1);
}
}
} 내가 .focus() 메소드를 사용하여 포커스를 설정하려고했습니다
하지만 그렇지 않습니다 작업. 나는 HTML에서 "onblur"에 의존 할 수 있다고 읽었습니다. Validate() 함수를 호출했을 때, 변경하려고 시도했지만 아무 것도 작동하지 않았습니다.
가능한 중복으로 설정 [경고 후 초점()를 제공하는 방법() ?] (http://stackoverflow.com/questions/7234190/how-to-give-focus-after-an-alert) – pasine