-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex-066.html
88 lines (75 loc) · 2.39 KB
/
ex-066.html
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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<meta charset="utf-8">
<title>jQuery 事件綜合練習: 新增 / 刪除節點與內容</title>
<style type="text/css">
</style>
</head>
<body>
<div class="container">
<table class="table table-striped">
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>@mdo</td>
<td><button class="btn btn-default del-profile">刪除</button></td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>@fat</td>
<td><button class="btn btn-default del-profile">刪除</button></td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>@twitter</td>
<td><button class="btn btn-default del-profile">刪除</button></td>
</tr>
</tbody>
<tfoot>
<tr>
<td>--</td>
<td>First Name: <input type="text" name="firstName" id="firstName" value=""></td>
<td>Last Name: <input type="text" name="lastName" id="lastName" value=""></td>
<td>Username Name: <input type="text" name="userName" id="userName" value=""></td>
<td><button class="btn btn-default add-profile">加入</button></td>
</tr>
</tfoot>
</table>
</div>
<script src="scripts/jquery-3.1.0.js"></script>
<script type="text/javascript">
// todo: 1. 當使用者按下 add-profile 按鈕時,tbody 內要加入對應的內容
$('.add-profile').on('click', function(){
console.log($('#firstName').val());
var insertFirstname = $('#firstName').val();
var insertLastname = $('#lastName').val();
var insertUsername = $('#userName').val();
var rowCount = $('.table tbody tr').length + 1;
console.log(insertFirstname);
//$('.table tbody tr').after()
$('.table tbody').append('<tr><th>'+rowCount+'</th><td>'+insertFirstname+'</td><td>'+insertLastname+'</td><td>@'+insertUsername+'</td><td><button class="btn btn-default del-profile">刪除</button></td></tr>');
});
// todo: 2. 完成 del 功能
$('tbody').on('click', '.del-profile', function(){
$(this).parents('tr').remove();
});
</script>
</body>
</html>