有做过北大青鸟培训讲师经验的我,如今在一家公司做技术部经理的职位,发现有很多程序员的基本功相当糟糕,在组织企业内部培训时讲解了一些案例,总结了一些经典代码,希望对自己和有需要的人提供一些帮助吧:
JavaScript版本:
DOM0事件不支持委托链
1 <!DOCTYPE html> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 5 <title>DOM0事件不支持委托链</title> 6 <script language="javascript" type="text/javascript"> 7 window.onload = function () { 8 //DOM0事件不支持委托链 9 document.getElementById("child").onclick = function () { 10 output("abc"); 11 }; 12 document.getElementById("child").onclick = function () { 13 output("123"); 14 }; 15 document.getElementById("child").onclick = function () { 16 output("def"); 17 }; 18 document.getElementById("child").onclick = function () { 19 output("456"); 20 }; 21 }; 22 23 function output(text) { 24 document.getElementById("content").innerHTML += text + "<br/>"; 25 } 26 </script> 27 </head> 28 <body > 29 <div > 30 <div > 31 点击这里 32 </div> 33 </div> 34 <div > 35 </div> 36 </body> 37 </html>