-
Notifications
You must be signed in to change notification settings - Fork 0
/
table.html
58 lines (58 loc) · 1.39 KB
/
table.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
table{
border: solid blue;
border-width: 1px 0px 0px 1px;
}
tr td,th{
border: solid blue;
border-width: 0px 1px 1px 0px;
text-align: center;
}
</style>
</head>
<body>
<form action="" id="myForm">
<label for="username">姓名:</label><input type="text" name="username" id="username" placeholder="请输入姓名"><br>
<label for="pwd">密码:</label><input type="password" name="pwd" id="pwd"><br>
<label for="phonenumber">手机号:</label><input type="text" name="phonenumber">
<button>序列化表单</button>
</form>
<table id="myTable">
<tr>
<th>id</th>
<th>name</th>
<th>age</th>
<th>hobby</th>
</tr>
</table>
</body>
<script src="js/jquery-1.10.2.min.js"></script>
<script>
$.ajax({
type: "POST",
url:"json.json",
datatype:"jsonp",
data:'',
jsonp:"callback",
success:function(data){
console.log("success!");
var str = '';
$.each(JSON.parse(data),function(index,item){//i表示的是{}括起来的组数的索引,n表示的是{}整个对象里的内容
// alert(n.name);
str += '<tr><td>'+item.id+'</td><td>'+item.name+'</td><td>'+item.age+'</td><td>'+item.hobby+'</td></tr>';
});
$("#myTable").append(str);
}
});
$(function(){
$('button').click(function(){
alert($("#myForm").serialize());
});
});
</script>
</html>