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'); }
下面是具体的应用
[Ctrl+A 全选 提示:你可先修改部分代码,再按运行]
如果是普通的html添加点击 这一段使得FireFox的HTMLElement具有click方法(add click method to HTMLElement in Mozilla)
复制代码 代码如下:
try { // create span element so that HTMLElement is accessible document.createElement('span'); HTMLElement.prototype.click = function () { if (typeof this.onclick == 'function') this.onclick({type: 'click'}); }; } catch (e) { // alert('click method for HTMLElement couldn\'t be added'); }