这一段使得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"); }
对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"); }