1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> |
---|
2 | <html xmlns="http://www.w3.org/1999/xhtml"> |
---|
3 | <head> |
---|
4 | <title>Test</title> |
---|
5 | <script type="text/javascript" src="jquery-1.3.js"></script> |
---|
6 | <script type="text/javascript"> |
---|
7 | $(document).ready(function () { |
---|
8 | |
---|
9 | $('#butt1').click(function (e) { |
---|
10 | $('#cb1').click(); |
---|
11 | }); |
---|
12 | $('#cb1').click(function (e) { |
---|
13 | $("#log").append("jQuery: "+this.checked+"<br />") |
---|
14 | // e.preventDefault(); |
---|
15 | // return false; |
---|
16 | }); |
---|
17 | |
---|
18 | document.getElementById("butt2").onclick = function(e){ |
---|
19 | e = e || event; |
---|
20 | document.getElementById("cb2").click(); |
---|
21 | }; |
---|
22 | document.getElementById("cb2").onclick = function(e){ |
---|
23 | e = e || event; |
---|
24 | var tgt = e.target || e.srcElement; |
---|
25 | document.getElementById("log").innerHTML += "Native DOM: "+tgt.checked+"<br />"; |
---|
26 | // if ( e.preventDefault ) |
---|
27 | // e.preventDefault(); |
---|
28 | // return false; |
---|
29 | }; |
---|
30 | |
---|
31 | $('#butt3').click(function (e) { |
---|
32 | $('#cb3')[0].click(); |
---|
33 | }); |
---|
34 | $('#cb3').click(function (e) { |
---|
35 | $("#log").append("jQuery+native: "+this.checked+"<br />") |
---|
36 | // e.preventDefault(); |
---|
37 | // return false; |
---|
38 | }); |
---|
39 | }); |
---|
40 | </script> |
---|
41 | </head> |
---|
42 | <body> |
---|
43 | |
---|
44 | jQuery: <button id="butt1">Check the checkbox!</button> |
---|
45 | <input type="checkbox" name="cb1" id="cb1" /> <br /> |
---|
46 | Native DOM: <button id="butt2">Check the checkbox!</button> |
---|
47 | <input type="checkbox" name="cb2" id="cb2" /> <br /> |
---|
48 | jQuery+native: <button id="butt3">Check the checkbox!</button> |
---|
49 | <input type="checkbox" name="cb3" id="cb3" /> <br /> |
---|
50 | |
---|
51 | <div id="log"></div> |
---|
52 | </body> |
---|
53 | </html> |
---|