如题:
 <script>
function initIt1(){
if(this.name == "idbmainlist"){parent.changeColor('007CD0');}
tableColl=document.all.tags("tr");
for(i=0; i<tableColl.length; i++) {
whichEl=tableColl(i);
if(whichEl.className=="child" && whichEl.id !="$Cookies{which}"){whichEl.style.display="none";}
}
}
function expands1(el) {
expireDate=new Date;
expireDate.setYear(expireDate.getYear()+1);
whichEl1=eval(el+"Child");
var wh = (el+"Child");
if (whichEl1.style.display=="none"){
initIt1();
whichEl1.style.display="block";
document.cookie="which="+wh+";expires="+expireDate.toGMTString()+";";
}else{
whichEl1.style.display="none";
document.cookie="which="+";expires="+expireDate.toGMTString()+";";
}
}
onload=initIt1;
    </script><script language="javascript" type="text/javascript">
    function printpage(myDiv){ 
     var oldstr = document.body.innerHTML; 
    document.getElementById("btnExcel").style.display="none";
     document.getElementById("Button2").style.display="none";
    var newstr = document.getElementById(myDiv).innerHTML;
     alert(newstr);
    window.print(); 
    document.body.innerHTML = oldstr; 
    return false; 
    } 
    </script>怎样改上面的代码,让所有的浏览器都支持?

解决方案 »

  1.   

    FF浏览器写JS一般要写全路径。例如:document.getElementById...在都加上document的前面加上window.***而且FF一般都是对BYNAME比较支持。。
    希望有帮助;
      

  2.   


    <script>
    function initIt1(){
    if(this.name == "idbmainlist"){parent.changeColor('007CD0');}
    tableColl=document.getElementsByTagName("tr");
    for(i=0; i<tableColl.length; i++) {
    whichEl=tableColl[i];
    if(whichEl.className=="child" && whichEl.id !="$Cookies{which}"){whichEl.style.display="none";}
    }
    }
    function expands1(el) {
    expireDate=new Date;
    expireDate.setYear(expireDate.getYear()+1);
    whichEl1=document.getElementById(el+"Child");
    var wh = document.getElementById(el+"Child");
    if (whichEl1.style.display=="none"){
    initIt1();
    whichEl1.style.display="block";
    document.cookie="which="+wh+";expires="+expireDate.toGMTString()+";";
    }else{
    whichEl1.style.display="none";
    document.cookie="which="+";expires="+expireDate.toGMTString()+";";
    }
    }
    onload=initIt1;
    </script><script language="javascript" type="text/javascript">
    function printpage(myDiv){ 
    var oldstr = document.body.innerHTML; 
    document.getElementById("btnExcel").style.display="none";
    document.getElementById("Button2").style.display="none";
    var newstr = document.getElementById(myDiv).innerHTML;
    alert(newstr);
    window.print(); 
    document.body.innerHTML = oldstr; 
    return false; 

    </script>还有报错的话,请上错误信息。
      

  3.   

    我把所有的代码都贴出来吧,我现在做的是,上面是一个横向的总菜单,左侧是一个树状的子菜单,然后是显示区域,我用了阿蛙的代码之后,在火狐里面还是不显示左侧菜单,  <script>
    function initIt1(){
        if(this.name == "idbmainlist"){parent.changeColor('007CD0');}
        tableColl=window.document.getElementsByTagName("tr");
        for(i=0; i<tableColl.length; i++) {
            whichEl=tableColl[i];
            if(whichEl.className=="child" && whichEl.id !="$Cookies{which}"){whichEl.style.display="none";}
        }
    }
    function expands1(el) {
        expireDate=new Date;
        expireDate.setYear(expireDate.getYear()+1);
        whichEl1=document.getElementById(el+"Child");
        var wh = document.getElementById(el+"Child");
        if (whichEl1.style.display=="none"){
            initIt1();
            whichEl1.style.display="block";
            document.cookie="which="+wh+";expires="+expireDate.toGMTString()+";";
        }else{
            whichEl1.style.display="none";
            document.cookie="which="+";expires="+expireDate.toGMTString()+";";
        }
    }
    onload=initIt1;
    </script>
        <link href="css/menu.css" rel="stylesheet" type="text/css">
    </head>
    <body leftmargin="0" topmargin="0">
        <form id="frmMenu" method="post" runat="server" style="height: 100%">
            <table height="100%" cellspacing="0" cellpadding="0" width="158" border="0">
                <tbody>
                    <tr>
                        <td colspan="3" height="25">
                            <img height="25" src="images/menu_files/left_r2_c1.gif" width="158"></td>
                    </tr>
                    <tr>
                        <td width="32" valign="top">
                            <table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td height="10">
                                        <img src="images/menu_files/left_r1_c1_2.gif" width="32" height="10"></td>
                                </tr>
                                <tr>
                                    <td valign="top" background="images/menu_files/left_r1_c1_1.gif">
                                        <img src="images/menu_files/left_r1_c1_1.gif" width="32" height="198" border="0"></td>
                                </tr>
                                <tr>
                                    <td height="10">
                                        <img src="images/menu_files/left_r1_c1_3.gif" width="32" height="10"></td>
                                </tr>
                            </table>
                        </td>
                        <td width="10" height="100%" valign="top">&nbsp;
                            
                        </td>
                        <td width="116" valign="top" background="images/menu_files/left_r4_c2.gif">
                            <table cellspacing="0" cellpadding="0" width="100%" align="center" border="0">
                                <tbody>
                                    <tr>
                                        <td align="middle" width="18">
                                            <a href="javascript:expands1('h0')">
                                                <img height="18" src="images/menu_files/t_plus.gif" width="17" border="0"></a></td>
                                        <td width="110" height="20">
                                            <a href="javascript:expands1('h0')">卡片管理</a></td>
                                    </tr>
                                    <tr class="child" id="h0Child">
                                        <td align="middle" colspan="2" height="22">
                                            <table height="20" cellspacing="0" cellpadding="0" width="100%" border="0">
                                                <tbody>
                                                    <tr id="TR1" runat="server">
                                                        <td align="middle" width="18" height="17">
                                                            <font color="#0066cc">·</font></td>
                                                        <td height="17">
                                                            <a href="Script/Issuing/GenerateCard.aspx"target="mainlist">生成卡号</a></td>
                                                    </tr>
                                                    <tr id="TR3" runat="server">
                                                        <td align="middle" width="18" height="17">
                                                            <font color="#0066cc">·</font></td>
                                                        <td height="17">
                                                            <a href="" target="mainlist">卡片激活</a></td>
                                                    </tr>
                                                     <tr id="TR2" runat="server">
                                                        <td align="middle" width="18" height="17">
                                                            <font color="#0066cc">·</font></td>
                                                        <td height="17">
                                                            <a href="" target="mainlist">卡片挂失</a></td>
                                                    </tr>
                                                     <tr id="TR4" runat="server">
                                                        <td align="middle" width="18" height="17">
                                                            <font color="#0066cc">·</font></td>
                                                        <td height="17">
                                                            <a href="" target="mainlist">卡片解挂</a></td>
                                                    </tr>
                                                     <tr id="TR5" runat="server">
                                                        <td align="middle" width="18" height="17">
                                                            <font color="#0066cc">·</font></td>
                                                        <td height="17">
                                                            <a href="" target="mainlist">卡片补办</a></td>
                                                    </tr>
                                                </tbody>
                                            </table>
                            
                </tbody>
            </table>
        </form>
      

  4.   

    <script>
    先改为
    <script type="text/javascript">
      

  5.   

    在FF中点击查看-页面风格-基本页面风格。就可以看到效果了。字符编码格式用GB2312或GBK查看;
      

  6.   

    document.all.tags对于火狐是不认识的,改为document.getElementByTagName("tr");应该就可以了
      

  7.   

    解决楼主的根本问题
    http://www.w3pop.com/learn/view/doc/js_ie_firefox_different_behave/