event.srcElement在火狐下的兼容问题——ie用event.srcElement,火狐用event.target

<span style="font-family:Microsoft YaHei;font-size:12px;">event.srcElement : 可以捕获当前事件作用的对象
<a href="#" onclick="test(event)"><img src="images/index_33-1.jpg" border="0"/></a>

<script language="javascript" type="text/javascript"> 
    function test(event) { 
        event = event? event: window.event
        var obj = event.srcElement ? event.srcElement:event.target; 
        if ( document.all) {
             obj.click();
        } else {
             var evt = document.createEvent("MouseEvents");
             evt.initEvent("click", true, true);
             obj.dispatchEvent(evt);
        } 
    } 
</script></span>


你可能感兴趣的:(JavaScript)