-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
39 lines (38 loc) · 1.15 KB
/
test.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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
</head>
<body>
<form name="form1">
<input type="checkbox" name="check[]" data-weight="5" /> 5<br />
<input type="checkbox" name="check[]" data-weight="10" /> 10<br />
<input type="checkbox" name="check[]" data-weight="30" /> 30<br />
</form>
<div>Total: <span id="total">0</span></div>
</body>
<script type="text/javascript">
(function () {
var totalEl = document.getElementById('total'),
total = 0,
checkboxes = document.form1['check[]'],
handleClick = function () {
total += parseInt(this['data-weight'], 10) * (this.checked ? 1 : -1);
totalEl.innerHTML = total;
},
i, l
;
for (i = 0, l = checkboxes.length; i < l; ++i) {
checkboxes[i].>
}
}());
</script>
</html>