JAVA/자바스크립트
자바스크립트 텍스트필드 빈칸체크예제
왕왕왕왕
2014. 9. 28. 16:01
<input type ="text" id = "text">
<input type = "submit" value = "버튼" onclick = "ckd()")
<script type="text/javascript">
window.onload = function() {
document.getElementById('text').focus();
}
function ckd() {
if (document.getElementById('text').value == "") {
alert("비었어요");
}
}
브라우저가 새로고침을 하면 text라는 id를 가진 태그에 포커스를 해준다.
text라는 id를 가진 태그의 값을 버튼 클릭 시에 체크하여 비어있다는 것을 체크해준다.