2013-07-03 8 views
0

자리 표시 자의 기본 유효성 검사 메시지를 변경할 수 있다면 관심이 있습니다.
맞춤 메시지를 작성하는 방법이어야합니다.HTML5 자리 표시자가 필요함 - 기본 메시지를 변경하십시오.

내 양식 :

<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>HTML5 Placeholder</title> 
</head> 

<body> 
    <form> 
     <input type="text" id="email" maxlength="35" placeholder="E-mail" required> 
     <button type="submit">Ok</button> 
    </form> 
</body> 
</html> 

나는 자바 스크립트으로 시도했지만 메시지는 매번 apears : [HTML5 양식 필수 속성의

<script type="text/javascript"> 
document.getElementById('email').setCustomValidity('Please enter your e-mail!'); 
</script> 
+1

가능한 중복. 사용자 지정 유효성 검사 메시지를 설정 하시겠습니까?] (http://stackoverflow.com/questions/5272433/html5-form-required-attribute-set-custom-validation-message) – djf

답변

0
<!doctype html> 
<html> 
<head> 
<meta charset="utf-8"> 
<title>Untitled Document</title> 
<script type='text/javascript' src='http://code.jquery.com/jquery-1.5.2.js'></script> 
</head> 

<body> 
    <form> 
     <input type="text" id="email" maxlength="35" placeholder="E-mail" required> 
     <button type="submit">Ok</button> 
    </form> 
    <script> 
    $(document).ready(function(){ 
    var elements = document.getElementsByTagName("INPUT"); 
    for (var i = 0; i < elements.length; i++){ 
     elements[i].oninvalid = function(e){ 
      e.target.setCustomValidity(""); 
      if (!e.target.validity.valid){ 
       e.target.setCustomValidity("This field cannot be left blank"); 
      } 
     }; 
     elements[i].oninput = function(e){ 
      e.target.setCustomValidity(""); 
     }; 
    } 
    }) 
    </script> 
</body> 

</html> 
관련 문제