JAVA_EE/JQuery
[JQuery] 아이디, 비밀번호 유효성 검사 & 일정 시간 후 서버로 정보 보내기
luvforjunk
2021. 10. 18. 15:32
728x90
반응형
[21.10.18] exam01(07_jQueryEvent) - 아이디, 비밀번호 유효성 검사 & 일정 시간 후 서버로 정보 보내기
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
* {
padding: 0;
margin: 0;
color: #333;
}
body {
padding: 20px 30px;
}
#login fieldset {
width: 270px;
padding: 15px;
border: 1px solid #7BAEB5;
position: relative;
}
#login fieldset legend {
display: none;
}
#login label {
display: inline-block;
width: 80px;
font-size: 14px;
font-weight: bold;
padding-left: 10px;
margin-bottom: 10px;
}
#login input[type='text'], #login input[type='password'] {
border: 1px solid #ccc;
padding: 3px 10px;
width: 150px;
vertical-align: middle;
font-size: 12px;
line-height: 150%;
}
#login input[type='submit'] {
width: 270px;
height: 20px;
}
.active {
border: 1px solid #f00 !important;
background-color: #98BF21;
}
#login {
position: relative;
}
#login fieldset .loader {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.3);
display: none;
}
#login .loader img {
position: absolute;
left: 50%;
top: 50%;
margin-left: -5px;
margin-top: -5px;
}
</style>
</head>
<body>
<form id="login">
<fieldset>
<legend>로그인</legend>
<div>
<label for="user_id">아이디</label> <input type="text" name="user_id"
id="user_id" />
</div>
<div>
<label for="user_password">비밀번호</label> <input type="password"
name="user_password" id="user_password" />
</div>
<div>
<input type="submit" value="로그인" />
</div>
<div class="loader">
<img src="../img/loader.gif" />
</div>
</fieldset>
</form>
<script type="text/javascript" src="http://code.jquery.com/jquery-3.6.0.min.js"></script>
<script type="text/javascript">
$(function(){
$('#user_id, #user_password').bind({
'focus' : function(){
$(this).addClass('active');
},
'blur' : function(){
$(this).removeClass('active');
}
});
$('#login').bind('click', function(){
if(!$('#user_id').val()) {
alert('아이디를 입력하세요.');
$('#user_id').focus();
return false;
}
if(!$('#user_password').val()) {
alert('비밀번호를 입력하세요.');
$('#user_password').focus();
return false;
}
$('#login .loader').show();
//나중에 아이디와 비밀번호를 서버로 보내는 작업을 하면 된다.
setTimeout(function(){
alert('안녕하세요. ' + $('#user_id').val() + '님');
$('#login .loader').hide();
}, 1000);
return false;
});
});
</script>
</body>
</html>
<!--
$(“요소”).bind( "이벤트", function() {
... 이벤트 처리 ...
});
$(“요소”).bind( "이벤트1 이벤트2 이벤트3", function() {
... 이벤트 처리 ...
});
$(“요소”).bind({
"이벤트1" : function() { ... 이벤트 처리 ...},
"이벤트2" : function() { ... 이벤트 처리 ...},
"이벤트3" : function() { ... 이벤트 처리 ...}
});
-->
[결과]
728x90
반응형