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 |
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
/*아이디 선택자가 #인 것을 지칭*/
#table1{width:70%}
#table2{width:50%}
table,th,td{border:1px solid black;text-align:center;}
</style>
<script type="text/javascript">
function add_go() {
//태그 생성
var td1=document.createElement("td");
var td2=document.createElement("td");
var td3=document.createElement("td");
var tr = document.createElement("tr");
//만들 태그에 문자(텍스트) 삽입
td1.innerHTML="1";
td2.innerHTML="fors";
td3.innerHTML="010-1234-5678";
//tr안에 td붙이기
tr.appendChild(td1);
tr.appendChild(td2);
tr.appendChild(td3);
//tbody에 tr붙이기
/* document.getElementById("tbody").appendChild(tr); */
document.getElementById("table1").children[2].appendChild(tr);
}
function delete_go() {
var my_tbody = document.getElementById('my-tbody');
if (my_tbody.rows.length < 1) return;
// my_tbody.deleteRow(0); // 상단부터 삭제
my_tbody.deleteRow( my_tbody.rows.length-1 ); // 하단부터 삭제
}
</script>
</head>
<body>
<table id="table1">
<thead>
<tr>
<th>번호</th>
<th>이름</th>
<th>전화</th>
</tr>
</thead>
<tfoot>
<tr>
<td>
<input type="button" value="추가" onclick="add_go()">
</td>
<td>
<input type="button" value="삭제" onclick="delete_go()">
</td>
</tr>
</tfoot>
<tbody id="my-tbody">
<tr></tr>
</tbody>
</table>
<table id="table2">
<thead>
<tr>
<th>번호</th>
<th>이름</th>
<th>전화</th>
</tr>
</thead>
<tbody id=>
<tr></tr>
</tbody>
<tfoot>
<tr>
<td colspan="3">
<input type="button" value="추가" onclick="add_go()">
</td>
</tr>
</tfoot>
</table>
</body>
</html> |
cs |
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 |
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>form과 function</title>
<style type="text/css">
fieldset { width: 450px}
</style>
<script type="text/javascript">
function send_go() {
var name = document.f.name.value ;
var age = document.f.age.value ;
var tel = document.f.tel.value ;
var pw = document.f.pw.value ;
var gender = document.f.gender.value;
var addr = document.f.addr.value;
var hobby = document.f.hobby;
var addr2 = document.f.addr2;
document.getElementById("res1").innerHTML = name;
document.getElementById("res2").innerHTML = age;
document.getElementById("res3").innerHTML = tel;
document.getElementById("res4").innerHTML = pw;
document.getElementById("res5").innerHTML = gender;
document.getElementById("res7").innerHTML = addr;
// 배열
var k2="";
for ( var k in hobby) {
if(hobby[k].checked==true){
k2 += hobby[k].value;
}
document.getElementById("res6").innerHTML =k2;
}
var k3="";
for ( var k in addr2) {
if(addr2[k].selected==true){
k3 += addr2[k].value+" ";
}
document.getElementById("res8").innerHTML =k3;
}
}
</script>
</head>
<body>
<form name="f">
<fieldset>
<legend>form 요소</legend>
<!-- 사용자가 입력한 값이 value속성의 값이다. -->
<p>이름 : <input type="text" name="name" placeholder="이름입력" /></p>
<p>나이 : <input type="number" name="age" placeholder="나이입력" /></p>
<p>전화 : <input type="tel" name="tel" /></p>
<p>비번 : <input type="password" name="pw" /></p>
<!-- 라디오버튼은 여러개중 하나만 선택 -->
<p> 성별 : <input type="radio" name="gender" value="남" />남자
<input type="radio" name="gender" value="여" />여자</p>
<!-- 체크박스 여러개중 여러개혹은 하나도 선택하지 않은것 -->
<!-- 여러개가 넘어온다. => 배열처리 -->
<p>
취미 :
<input type="checkbox" name="hobby" value="축구" />축구
<input type="checkbox" name="hobby" value="야구" />야구
<input type="checkbox" name="hobby" value="농구" />농구
<input type="checkbox" name="hobby" value="배구" />배구
</p>
<!-- 하나만선택 -->
<p>
거주지 : <select name="addr">
<option>선택하세요</option>
<option value="서울">서울</option>
<option value="대구">대구</option>
<option value="대전">대전</option>
<option value="부산">부산</option>
<option value="광주">광주</option>
</select>
</p>
<!-- 여러개 선택 가능 -->
<p>
거주지2 : <select name="addr2" multiple>
<option>선택하세요</option>
<option value="서울">서울</option>
<option value="대구">대구</option>
<option value="대전">대전</option>
<option value="부산">부산</option>
<option value="광주">광주</option>
</select>
</p>
<p><input type="button" value="전달" onclick="send_go()"> </p>
</fieldset>
</form>
<br />
<hr />
<h2>
<ul>
<li>이름 : <span id="res1"></span></li>
<li>나이 : <span id="res2"></span></li>
<li>전화 : <span id="res3"></span></li>
<li>비번 : <span id="res4"></span></li>
<li>성별 : <span id="res5"></span></li>
<li>취미 : <span id="res6"></span></li>
<li>거주지 : <span id="res7"></span></li>
<li>거주지2 : <span id="res8"></span></li>
</ul>
</h2>
</body>
</html>
|
cs |
'HTML│CSS│Java Script' 카테고리의 다른 글
html 전구 켜고 끄기 (0) | 2017.12.06 |
---|---|
html 표 추가 삭제 (0) | 2017.12.06 |
자바 스크립트 배열 (0) | 2017.12.05 |
자바스크립트 (0) | 2017.12.04 |
html table / div / iframe 태그 작성하는 방법 (0) | 2017.12.04 |
댓글