-
Notifications
You must be signed in to change notification settings - Fork 0
/
2.html
122 lines (117 loc) · 4.16 KB
/
2.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
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
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<style>
td {
width: 25%;
}
</style>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
<body>
<table border="1" cellpadding="0" cellspacing="0" style="width: 100%;">
<tr>
<td>物品</td>
<td>数量</td>
<td>金额</td>
<td>备注</td>
</tr>
<tr>
<td><span id="clothSpan" style="cursor: pointer">+</span> <span>服装</span></td>
<td>100件</td>
<td>12000元</td>
<td></td>
</tr>
<tr style="display: none">
<td></td>
<td colspan="3" style="width: 75%">
<div>
<table border="1" style="position: relative;width: 500px;height: 100px;left: 30%;margin-top: 25px">
<tr>
<td>明细</td>
<td>数量</td>
<td>单价</td>
<td>备注</td>
</tr>
<tr>
<td>外套</td>
<td>10</td>
<td>300</td>
<td></td>
</tr>
<tr>
<td>裤子</td>
<td>90</td>
<td>100</td>
<td></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td><span id="fruitSpan" style="cursor: pointer">+</span> <span>水果</span></td>
<td>100KG</td>
<td>290元</td>
<td></td>
</tr>
<tr style="display: none">
<td></td>
<td colspan="3" style="width: 75%">
<table border="1" style="position: relative;width: 500px;height: 100px;left: 30%;margin-top: 25px">
<tr>
<td>明细</td>
<td>重量</td>
<td>单价</td>
<td>备注</td>
</tr>
<tr>
<td>西瓜</td>
<td>10</td>
<td>20</td>
<td></td>
</tr>
<tr>
<td>柚子</td>
<td>9</td>
<td>10</td>
<td></td>
</tr>
</table>
</td>
</tr>
</table>
</body>
<script>
var showElement = function (event) {
console.log(event); //这个event是Jquery的event,包含了很多
console.log(event.data.spanElement);//我们参数的值就按键值对放在event.data里
console.log(event.data.aaa);
console.log(event.data.bbb);
var tr = event.data.spanElement.parentElement.parentElement;
var nextTr = tr.nextElementSibling;
if (nextTr.style.display === "none") {
nextTr.style.display = "table-row";
tr.cells[0].firstChild.textContent = "-";
} else {
nextTr.style.display = "none";
tr.cells[0].firstChild.textContent = "+";
}
};
var arg1 = {
spanElement: document.getElementById("clothSpan"),
aaa: 1,
bbb: "qwe"
}
$("#clothSpan").click(arg1, showElement);
var arg2 = {
spanElement: document.getElementById("fruitSpan"),
}
$("#fruitSpan").click(arg2, showElement);
//click(data,fn)中的data其实是json对象,取的时候,只能通过当前的事件源来取,
// data是默认放在event中的,所以这里的data是eventdata,引用的时候也使用event.data.name,
// 也就是说JQuery中的所有触发时间的方法,需要传递参数都可以通过eventdata对象来传递参数:
</script>
</html>