JavaScript Var 'Undefined' in Firefox; IE and Opera Work fine
2011-01-14 16:28
597 查看
I have some JavaScript that works fine in IE and Opera, but not Firefox.
The issue seems to be that Firefox is seeing the variable as undefined.
Do I have to declare that variable even though it should be inherited?
Your problem is that you're using document.all, and .innerText, neither of which are standard.
You should be using document.getElementById() to grab items, and .innerHTML to read their contents, if they're not form inputs.
If they are inputs, use .value instead of .innerText
Firfox支持:document.getElementById("c0").textContent
IE支持: document.getElementById("c0").innerText
The issue seems to be that Firefox is seeing the variable as undefined.
Do I have to declare that variable even though it should be inherited?
Your problem is that you're using document.all, and .innerText, neither of which are standard.
You should be using document.getElementById() to grab items, and .innerHTML to read their contents, if they're not form inputs.
If they are inputs, use .value instead of .innerText
Firfox支持:document.getElementById("c0").textContent
IE支持: document.getElementById("c0").innerText
<mce:script language="javascript" ><!-- function isIE(){ //alert("") //alert(window.navigator.userAgent) //alert(window.navigator.userAgent.toString().toLowerCase().indexOf("msie")) if (window.navigator.userAgent.toString().toLowerCase().indexOf("msie") >=1) return true; else return false; } //alert(isIE()) 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; } ); } alert(document.getElementById("aaaa").textContent) alert(document.getElementById("aaaa").innerText) // --></mce:script>
相关文章推荐
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- Notice: Use of undefined constant INTL_ICU_VERSION - assumed 'INTL_ICU_VERSION' in D:\work\WWW\basic
- angular this vs $scope (How does 'this' and $scope work in AngularJS controllers?)
- User javascript to catch ctrl in IE and Firefox
- Firefox is currently in offline mode and can't browse the Web
- [JavaScript]Event Object in FireFox and IE
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- firefox 下 'innerText' works in IE, but not in Firefox
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- Get the content of an Iframe in Javascript – crossbrowser solution for both IE and Firefox
- javascript小组件 原生脚本排序table表格兼容ie firefox opera chrome 浏览器
- Uboot编译出下如下错误的一个原因:In function `__aeabi_ldiv0': (.text+0x8): undefined reference to `raise'
- no plugin found for prefix 'tomcat 7' in the current project and in the plugin groups
- 微信支付Notice: Use of undefined constant CURLOP_TIMEOUT - assumed 'CURLOP_TIMEOUT' in
- No plugin found for prefix 'jetty' in the current project and in the plugin groups
- IE/FF/OP兼容的JavaScript放大镜( magnifying glass by JS work in IE/FF/OP)
- 关于ERROR: 'rake/rdoctask' is obsolete and no longer supported. Use 'rdoc/task' (available in RDoc
- js实时时间显示,兼容IE、Opera、Firefox,javascript面向对象编程。
- javascript获取select的当前值示例代码(兼容IE/Firefox/Opera/Chrome)