You may have encountered a situation in your project before. You can click the same html component to execute different methods or functions. So I wrote the following method myself, which is stupid, but still executable.
The core code is as follows:
1. <script>
2. <! --
3 ./*
4. * function: use JavaScript to modify the onclick event execution method in the component.
5. * Creator: FrancisRan
6. * Creation Time: 2010-07-30
7. * last modification time: 2010-07-30
8. * copyright (c) 2010 ranfanwei1988@126.com
9 .*/
10.
11. // modify the onclick event Value
12. function addEvent (){
13. alert ("onclick before modification: \ n" + document. getElementById ("eventTest"). onclick );
14.
15. // modify the onclick value of the eventTest component
16. document. getElementById ("eventTest"). onclick = alertEvent2;
17.
18. alert ("modified onclick: \ n" + document. getElementById ("eventTest"). onclick );
19. alert ("modified successfully, click" pop-up "to view the effect ");
20 .}
21.
22. // events before modification
23. function alertEvent (){
24. alert ("this is an event not triggered by deletion ");
25 .}
26.
27. // modified event
28. function alertEvent2 (){
29. alert ("this is the event triggered after deletion ");
30 .}
31. -->
32. </script>
33.
34. <input type = "button" id = "eventTest" onclick = "alertEvent ()" value = "pop-up"/>
35. <input type = "button" onclick = "addEvent ()" value = "modify"/>
This article is from the "FrancisRan" blog