当前位置:Gxlcms > 
JavaScript > 
Javascript模拟点击事件(点击链接与html点击)兼容IE/Firefox_javascript技巧
                     
                    
                        Javascript模拟点击事件(点击链接与html点击)兼容IE/Firefox_javascript技巧
                        
                            时间:2021-07-01 10:21:17
                            帮助过:34人阅读
							                        
                     
                    
                    一把情况下模拟点击一般两个方面,模拟点击超级连接事件
firefox的兼容的函数为
对HTMLAnchorElement 加入onclick事件  代码如下:
try { 
// create a element so that HTMLAnchorElement is accessible 
document.createElement('a'); 
HTMLElement.prototype.click = function () { 
if (typeof this.onclick == 'function') { 
if (this.onclick({type: 'click'}) && this.href) 
window.open(this.href, this.target? this.target : '_self'); 
} 
else if (this.href) 
window.open(this.href, this.target? this.target : '_self'); 
}; 
} 
catch (e) { 
// alert('click method for HTMLAnchorElement couldn\'t be added'); 
} 
下面是具体的应用