利用事件冒泡(Event Bubbling )获取鼠标下的元素属性
<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF8"> <title>事件冒泡应用实例</title> <style type="text/css" > .button { color: blue; width: 120px; } </style> <script type="text/javascript" defer="defer"> function init(){ try { document.onmousemove = update; } catch(e) { alert(e); } } function update(e){ e = e || window.event; var cameFrom = e.toElement ? e.toElement : e.explicitOriginalTarget; //event source cameFrom = (cameFrom || (e.srcElement ? e.srcElement : e.fromElement)); if(typeof cameFrom != 'undefined' && cameFrom != null) { var theId = cameFrom.getAttribute("id"); var theName = cameFrom.getAttribute("name"); var theClass = cameFrom.className; document.getElementById("status").innerHTML = "id=[" +( theId || ' ') + "] name=[" +( theName || ' ') + "] class=[" +( theClass || ' ') + "]"; }else { } } </script> </head> <body onload="init();"> <input type = "text " size = "20" name = "test1" /><br/> <input type = "button" name = "test2" /><br/> <input type = "button" class= "button" name = "test3" /><br/> <input type = "checkbox" id = "id3" /><br/> <hr color="#fe3300"/> <div id="status" ></div> </body> </html>