日期:2014-05-16 浏览次数:20388 次
<html> 2 <head> 3 <script language="javascript"> 4 function hello222(){ 5 for (var i=1; i<3; i++){ 6 var cell = document.getElementById("cell_"+i); 7 cell.onclick= function (i) {alert ('Removed 000 !! in goodbye!!!' + " " + i );} 8 } 9 } 10 11 function hello(){ 12 alert ("old on click!!"); 13 } 14 15 16 function goodbye(passed){ 17 alert ('Removed !! in goodbye!!!' + " " + passed ); 18 } 19 </script> 20 </head> 21 <body> 22 <a onclick="hello()" id="cell_1">me1</a> 23 <a onclick="hello()" id="cell_2">me2</a> 24 <p> 25 <input type="button" value="remove onclick" onclick="hello222()"> 26 </body> 27 </html>
<html> <head> <script language="javascript"> function hello222(){ for (var i=1; i<3; i++){ var cell = document.getElementById("cell_"+i); cell.onclick= new Function("hello_new('" + i + "');"); } } function hello(){ alert("old on click!!"); } function hello_new(passed){ alert('Removed !! in goodbye!!!' + " " + passed ); } </script> </head> <body> <a onclick="hello()" id="cell_1">me1</a> <a onclick="hello()" id="cell_2">me2</a> <p> <input type="button" value="remove onclick" onclick="hello222()"> </body> </html>