项目在做到一个弹出层的时候,与foxfire出现了兼容性问题,在IE里边一切都正常,但是foxfire里边就是什么都弹不出来,或则弹出来又乱码.关闭也关闭不了,commit也无法操作,后来利用firefox自带的firebug进行debug,终于把所有问题基本解决,以下罗列出现的所有问题,希望对以后有帮助.
1.select选择框查找选中的问题.
var c = document.getElementById("selProductStatus");
for (var count=0;count<c.options.length ;count++ )
{
//此时选择c.options[count],在IE下边有效。但在firfox下不会兼容。必须要c.options.item(count)
if (c.options.item(count).value==status)
{
c.selectedIndex =count;
}
}
2.innerText的问题,firfox不支持innerText的说法.解决方法是加上以下代码:for (var count=0;count<c.options.length ;count++ )
{
//此时选择c.options[count],在IE下边有效。但在firfox下不会兼容。必须要c.options.item(count)
if (c.options.item(count).value==status)
{
c.selectedIndex =count;
}
}
//convert innerText to fix the foxfire
function isIE(){ //ie?
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;
anyString += childS[i].innerText;
else if(childS[i].nodeType==3)
anyString += childS[i].nodeValue;
}
return anyString;
}
);
HTMLElement.prototype.__defineSetter__("innerText",
function(sText){
this.textContent=sText;
}
);
}
function isIE(){ //ie?
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;
anyString += childS[i].innerText;
else if(childS[i].nodeType==3)
anyString += childS[i].nodeValue;
}
return anyString;
}
);
HTMLElement.prototype.__defineSetter__("innerText",
function(sText){
this.textContent=sText;
}
);
}
3.区分id大小写问题
function closeDiv(_sID)
{
//传入的string必须区分打小写,比如有个div的id 为'Test',那么传入的值就必须是'Test',但是ie中大小写都可以.
var oObj = $(_sID);
//oObj.style.display = "";
oObj.style.display = "none";
}
{
//传入的string必须区分打小写,比如有个div的id 为'Test',那么传入的值就必须是'Test',但是ie中大小写都可以.
var oObj = $(_sID);
//oObj.style.display = "";
oObj.style.display = "none";
}
4.xml解析问题
//update触发ajax事件处理后触发事件。
function updateResult()
{
if(xmlHttp.readyState==4)//服务器响应状态
{
if(xmlHttp.status==200)//代码执行状态
{
if(window.ActiveXObject){//IE 进入此处处理
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM") ;
xmlDoc.async="false" ;
xmlDoc.loadXML(xmlHttp.responseText);
var nodes = xmlDoc.documentElement.childNodes ;
var id0 = nodes.item(0).getAttribute("id");
var id1 = nodes.item(1).getAttribute("id");
document.getElementById(id0).innerText = nodes.item(0).text;
document.getElementById(id1).innerText = nodes.item(1).text;
alert('update complete!');
}
}else {//firefox 进入此处处理
var oParser =new DOMParser();
var oXmlDom = oParser.parseFromString(xmlHttp.responseText,"text/xml");
var id0 = oXmlDom.documentElement.childNodes[0].attributes[0].nodeValue ;
var id1 = oXmlDom.documentElement.childNodes[1].attributes[0].nodeValue ;
document.getElementById(id0).innerText = oXmlDom.documentElement.childNodes[0].textContent;
document.getElementById(id1).innerText = oXmlDom.documentElement.childNodes[1].textContent;
alert('update complete!');
}
}
// var xmlDom = startGetXML();
// window.alert(xmlHttp.responseText);
}
}
}
function updateResult()
{
if(xmlHttp.readyState==4)//服务器响应状态
{
if(xmlHttp.status==200)//代码执行状态
{
if(window.ActiveXObject){//IE 进入此处处理
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM") ;
xmlDoc.async="false" ;
xmlDoc.loadXML(xmlHttp.responseText);
var nodes = xmlDoc.documentElement.childNodes ;
var id0 = nodes.item(0).getAttribute("id");
var id1 = nodes.item(1).getAttribute("id");
document.getElementById(id0).innerText = nodes.item(0).text;
document.getElementById(id1).innerText = nodes.item(1).text;
alert('update complete!');
}
}else {//firefox 进入此处处理
var oParser =new DOMParser();
var oXmlDom = oParser.parseFromString(xmlHttp.responseText,"text/xml");
var id0 = oXmlDom.documentElement.childNodes[0].attributes[0].nodeValue ;
var id1 = oXmlDom.documentElement.childNodes[1].attributes[0].nodeValue ;
document.getElementById(id0).innerText = oXmlDom.documentElement.childNodes[0].textContent;
document.getElementById(id1).innerText = oXmlDom.documentElement.childNodes[1].textContent;
alert('update complete!');
}
}
// var xmlDom = startGetXML();
// window.alert(xmlHttp.responseText);
}
}
}