-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinline.html
More file actions
198 lines (157 loc) · 4.64 KB
/
inline.html
File metadata and controls
198 lines (157 loc) · 4.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
<%@page language="java" contentType="text/html; charset=utf-8" %>
<%@ taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core' %>
<%@ taglib prefix='fn' uri='http://java.sun.com/jsp/jstl/functions' %>
<%@page isELIgnored="false"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
label {
display: inline-block;
width: 480px;
}
</style>
</head>
<body>
<ul>
<li>
<input type="button" name="btn-new" value="#1.신규입력">
</li>
<li></li>
<li>
<input type="hidden" name="deptno" value="">
<span for="input2">dname</span>
<input type="text" id="input2" name="dname" value="">
<span for="input3">dname</span>
<input type="text" id="input3" name="dloc" value="">
<input type="button" name="btn-insert" value="#1.저장">
</li>
</ul>
<ul class="uldata">
<c:forEach items="${list}" var="data">
<li data-deptno=${data.deptno}>
<label>${data.dname} / ${data.dloc} </label>
<input type="button" name="btn-modify" value="수정">
<input type="button" name="btn-delete" value="삭제">
</li>
</c:forEach>
</ul>
<script src="https://code.jquery.com/jquery-2.2.4.js"></script>
<script>
$(document).ready(function () {
var selected = {};
$('[name="btn-new"]').on('click', function() {
selected = {};
$('[name="dname"]').val('');
$('[name="dloc"]').val('');
$('[name="deptno"]').val('');
});
$('[name="btn-insert"]').on('click', function(){
if($('[name="dname"]').val() == '') {
alert('내용을 입력해주세요');
return ;
}
if($('[name="dloc"]').val() == '') {
alert('내용을 입력해주세요');
return ;
}
var obj = {
"act": "employInsert",
"dname": $('[name="dname"]').val(),
"dloc": $('[name="dloc"]').val()
};
$.ajax({
type: "post",
url: "./test1.do",
data: obj,
success: function (response) {
alert('저장되었습니다');
location.href='./test1.do';
}, error: function(response) {
console.log(response);
}
});
});
$(document).on('click','[name="btn-delete"]', function() {
debugger
var obj = {
"act": "employDelete",
"deptno": $(this).closest('li').data('deptno')
}
$.ajax({
type: "post",
url: "./test1.do",
data: obj,
success: function (response) {
alert('삭제되었습니다');
location.href = './test1.do';
}
});
});
var prevTr = '';
var prevNum = '';
$(document).on('click','[name="btn-modify"]', function() {
if(prevNum != $(this).closest('li').data('deptno')) {
if(prevNum != '') {
$('[data-deptno='+ prevNum + ']').html(prevTr);
}
//==================================================
prevTr = $(this).closest('li').html();
prevNum = $(this).closest('li').data('deptno');
var _deptno_ = $(this).closest('li');
var str = '<label>';
str += '<input type="hidden" name="deptno" value="">';
str += '<input type="text" id="input2" name="dname" value="">';
str += '<input type="text" id="input3" name="dloc" value="">';
str += '</label>';
str += '<input type="button" name="btn-update" value="#2.저장">';
$(_deptno_).html(str);
$.ajax({
url: "./test1.do",
data: "act=selectOne&deptno="+ $(_deptno_).data('deptno') ,
dataType: "json",
success: function (response) {
var data = response;
$(_deptno_).find('[name="dname"]').val(data.dname);
$(_deptno_).find('[name="dloc"]').val(data.dloc);
$(_deptno_).find('[name="deptno"]').val(data.deptno);
selected = response;
}
});
}
});
$(document).on('click','[name="btn-update"]', function() {
if($('[name="dname"]').val() == '') {
alert('내용을 입력해주세요');
return ;
}
if($('[name="dloc"]').val() == '') {
alert('내용을 입력해주세요');
return ;
}
var obj = {
"act": "employUpdate",
"deptno": selected.deptno,
"dname": $('[name="dname"]').val(),
"dloc": $('[name="dloc"]').val()
};
$.ajax({
type: "post",
url: "./test1.do",
data: obj,
success: function (response) {
alert('저장되었습니다');
location.href='./test1.do';
}, error: function(response) {
console.log(response);
}
});
})
});
</script>
</body>
</html>