源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

让firefox支持IE的一些方法的javascript扩展函数代码

  • 时间:2020-03-29 09:54 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:让firefox支持IE的一些方法的javascript扩展函数代码
[b]这一段使得FireFox也支持IE的innerText方法 [/b]
[u]复制代码[/u] 代码如下:
function isIE(){ if (window.navigator.userAgent.toLowerCase().indexOf("msie")>=1) return true; else return false; } if(!isIE()){ //firefox innerText define HTMLElement.prototype.__defineGetter__( "innerText", function(){ var anyString = ""; var childS = this.childNodes; for(var i=0; i <childS.length; i++) { if(childS[i].nodeType==1) anyString += childS[i].tagName=="BR" ? '\n' : childS[i].innerText; else if(childS[i].nodeType==3) anyString += childS[i].nodeValue; } return anyString; } ); HTMLElement.prototype.__defineSetter__( "innerText", function(sText){ this.textContent=sText; } ); }
[b]这一段使得FireFox的HTMLElement具有click方法[/b](add click method to HTMLElement in Mozilla)
[u]复制代码[/u] 代码如下:
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'); }
[b]对HTMLAnchorElement 加入onclick事件 [/b]
[u]复制代码[/u] 代码如下:
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'); }
[b]跟踪回车键事件[/b]
[u]复制代码[/u] 代码如下:
function captureKeys (evt) { var keyCode = evt.keyCode ? evt.keyCode : evt.charCode ? evt.charCode : evt.which; if (keyCode == 13) { // cancel key: if (evt.preventDefault) { evt.preventDefault(); } var dq = getCookie('default-engine'); if( dq == null) dq = "baidu_txt"; submit_query( dq ); return false; } return true; }
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部