我用SCRIPT语言在html页面写了一个函数:
<SCRIPT language="javascript">
function show(tabid,imgid){
                       if(tabid.style.display!='none')
                               {
                           imgid.src='../Common/images/arrow_show.gif';
                           tabid.style.display='none';
                       }
                       else
                               {
                           imgid.src='../Common/images/arrow_hide.gif';
                           tabid.style.display='block';
                       }
}
</SCRIPT>
在某处调用这个函数,<td align="right" width="11%"><IMG id="ImageButton11" onclick="javascript:show(table_index,ImageButton11)" src="../Common/images/arrow_hide.gif"
height="21"></td>,可以实现折叠功能。
而在另一个地方调用该函数,却报网页有错误,写发都是一样的,为什么会出现这个问题,请高手指点,程序如下:<td align="right" width="11%"><IMG id="ImageButton10" onclick="javascript:show(table_line,ImageButton10)" src="../Common/images/arrow_show.gif"
height="21"></td>
我个人总结的是,只有当该区域默认展开时,才有效;默认为收缩时,报错。是否我的函数写的不对,'none'和'block'分别表示什么意思?

解决方案 »

  1.   

    none,block分别代表隐藏和显示function show(tabid,imgid){
     if(document.getElementById(tabid).style.display!='none')
    {
    document.getElementById(imgid).src='../Common/images/arrow_show.gif';
    document.getElementById(tabid).style.display='none';}
    ....
    下面类似修改"><IMG id="ImageButton10" onclick="javascript:show('table_line','ImageButton10')" 调用
      

  2.   

    block Object is rendered as a block element. 
    none Object is not rendered. 我觉得显示隐藏都应该可以的。
    到WEB的Javascript中去问问
      

  3.   

    net_lover(孟子E章) ,你好,我按你说的改了,如下:
    <td style="HEIGHT: 5px" align="right" width="11%"><IMG id="ImageButton10" onclick="javascript:show('table_line','ImageButton10')" src="../Common/images/arrow_show.gif"
    height="21"></td>
    <td align="right" width="11%"><IMG id="ImageButton11" onclick="javascript:show('table_index','ImageButton11')" src="../Common/images/arrow_hide.gif"
    height="21"></td>
    <SCRIPT language="javascript">
    function show(tabid,imgid){
                           if(document.getElementById(tabid).style.display!='none')
                                   {
                               document.getElementById(imgid).src='../Common/images/arrow_show.gif';
                               document.getElementById(tabid).style.display='none';
                           }
                           else
                                   {
                               document.getElementById(imgid).src='../Common/images/arrow_hide.gif';
                               document.getElementById(tabid).style.display='block';
                           }
    }
    </SCRIPT>运行时,'ImageButton11'可以用,但点击'ImageButton10'时报“网页有错误”
      

  4.   

    请用我这个:
    <html><head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <meta name="GENERATOR" content="Microsoft FrontPage 4.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <title>New Page 4</title>
    <base target="main">
    <script language=JavaScript1.2>
    scores = new Array(20);
    var numTotal=0;
    NS4 = (document.layers) ? 1 : 0;
    IE4 = (document.all) ? 1 : 0;
    ver4 = (NS4 || IE4) ? 1 : 0;if (ver4) {
        with (document) {
            write("<STYLE TYPE='text/css'>");
            if (NS4) {
                write(".parent {position:absolute; visibility:visible}");
                write(".child {position:absolute; visibility:visible}");
                write(".regular {position:absolute; visibility:visible}")
            }
            else {
                write(".child {display:none}")
            }
            write("</STYLE>");
        }
    }function getIndex(el) {
        ind = null;
        for (i=0; i<document.layers.length; i++) {
            whichEl = document.layers[i];
            if (whichEl.id == el) {
                ind = i;
                break;
            }
        }
        return ind;
    }function arrange() {
        nextY = document.layers[firstInd].pageY +document.layers[firstInd].document.height;
        for (i=firstInd+1; i<document.layers.length; i++) {
            whichEl = document.layers[i];
            if (whichEl.visibility != "hide") {
                whichEl.pageY = nextY;
                nextY += whichEl.document.height;
            }
        }
    }function initIt(){
        if (!ver4) return;
        if (NS4) {
            for (i=0; i<document.layers.length; i++) {
                whichEl = document.layers[i];
                if (whichEl.id.indexOf("Child") != -1) whichEl.visibility = "hide";
           }
            arrange();
        }
        else {
            divColl = document.all.tags("DIV");
            for (i=0; i<divColl.length; i++) {
                whichEl = divColl(i);
                if (whichEl.className == "child") whichEl.style.display = "none";
            }
        }
    }function expandIt(el) {
    if (!ver4) return;
        if (IE4) {
            whichEl1 = eval(el + "Child");
    for(i=1;i<=numTotal;i++){
    whichEl = eval(scores[i] + "Child");
    if(whichEl!=whichEl1) {
    whichEl.style.display = "none";
    }
    }
            whichEl1 = eval(el + "Child");
            if (whichEl1.style.display == "none") {
                whichEl1.style.display = "block";
            }
            else {
                whichEl1.style.display = "none";
            }
        }
        else {
            whichEl = eval("document." + el + "Child");
    for(i=1;i<=numTotal;i++){
    whichEl = eval("document." + scores[i] + "Child");
    if(whichEl!=whichEl1) {
    whichEl.visibility = "hide";
    }
    }
            if (whichEl.visibility == "hide") {
                whichEl.visibility = "show";
            }
            else {
                whichEl.visibility = "hide";
            }
            arrange();
        }
    }
    onload = initIt;
    </script>
    </head><body>
    <div id=KB1Parent>
     <a onClick="expandIt('KB1');return false"><img src="images/plus.gif" border=0 width="31" height="14">酒店管理</a>
    </div>
    <div class=child id=KB1Child>
    <img src="images/blank.gif" border=0><a href="Hotal/add_jiudian.asp">添加酒店</a><br> 
    <img src="images/blank.gif" border=0><a href="Hotal/add_fangxing.asp">添加房型</a><br> 
    <img src="images/blank.gif" border=0><a href="Hotal/other_uploadPic.asp">上传图片</a><br>
    <img src="images/blank.gif" border=0><a href="Hotal/Hours_List.asp">房型列表</a><br> 
    <img src="images/blank.gif" border=0><a href="Hotal/Hotal_List.asp">酒店列表</a> 
    </div>
    <div  id=KB2Parent>
     <a onClick="expandIt('KB2');return false"><img src="images/plus.gif" border=0>机票管理</a>
    </div>
    <div class=child id=KB2Child>
    <img src="images/blank.gif" border=0><a href="JiPiao/add_Hangban.asp">添加航班</a><br>
            <img src="images/blank.gif" border=0><a href="JiPiao/Jipiao_list.asp">机票列表</a><br>

    </div><script>numTotal=2;scores[1]='KB1';scores[2]='KB2';</script>
    </body></html>
      

  5.   

    'table_line'???
    有这个ID嘛????
      

  6.   

    'table_line'???
    有这个ID嘛????
      

  7.   

    下面把我的完整代码贴出来,希望大家帮我分析:
    报错的地方代码如下:
    <table cellSpacing="0" cellPadding="0" width="100%" border="0">
    <tr>
    <td bgColor="#89d7fe" height="1"><FONT face="宋体"></FONT></td>
    </tr>
    </table>
    <table style="WIDTH: 839px" cellSpacing="0" cellPadding="0" width="839" border="0">
    <tr>
    <td align="left" colSpan="4" height="5"><FONT face="宋体"></FONT></td>
    </tr>
    <tr>
    <td style="HEIGHT: 5px" align="left" width="9%"><FONT face="宋体">&nbsp;&nbsp;<asp:label id="Label_Line" runat="server">工艺路线</asp:label></FONT></td>
    <td style="HEIGHT: 5px" width="30%"><asp:dropdownlist id="DDL_Line" runat="server" Width="100%" AutoPostBack="True"></asp:dropdownlist></td>
    <td style="HEIGHT: 5px" width="50%"><FONT face="宋体"></FONT></td>
    <td style="HEIGHT: 5px" align="right" width="11%"><IMG id="ImageButton10" onclick="javascript:show(table_line,ImageButton10)" src="../Common/images/arrow_hide.gif"
    height="21"></td>
    </tr>
    <tr>
    <td align="left" colSpan="4" height="1"><FONT face="宋体"></FONT></td>
    </tr>
    <tr>
    <td></td>
    </tr>
    </table>
    <table>
    <tr>
    <td>
    <table id="table_line" style="WIDTH: 839px" cellSpacing="0" cellPadding="0" width="839"
    border="0" runat="server">
    <tr>
    <td align="left" colSpan="2" height="1"><FONT face="宋体"></FONT></td>
    </tr>
    <tr>
    <td vAlign="top" align="left" width="9%"><FONT face="宋体">&nbsp;&nbsp;<asp:label id="Label_LineCompose" runat="server">路线组成</asp:label></FONT></td>
    <td vAlign="top" align="left" width="91%" height="150"><FONT face="宋体"><iewc:treeview id="RTV_ProcCompose" runat="server" height="150" width="99.5%"></iewc:treeview></FONT></td>
    </tr>
    <tr>
    <td align="left" colSpan="2" height="1"><FONT face="宋体"></FONT></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>可以正确使用的代码如下:
    <table id="table_liebiao" style="WIDTH: 839px" cellSpacing="0" cellPadding="0" width="839"
    border="0" runat="server">
    <tr>
    <td align="left" colSpan="4" height="5"><FONT face="宋体"></FONT></td>
    </tr>
    <tr>
    <td align="left" width="9%"><FONT face="宋体">&nbsp;&nbsp;<asp:label id="Label1" runat="server">参数列表</asp:label></FONT></td>
    <td width="30%"><FONT face="宋体"><asp:label id="Label_Starttime" runat="server" Visible="False">启用时间</asp:label><asp:textbox id="TB_Starttime" onfocus="dateTimeBox()" runat="server" Width="144px" Visible="False"
    BackColor="White" BorderColor="#89D7FE"></asp:textbox></FONT></td>
    <td width="50%"><FONT face="宋体"></FONT></td>
    <td align="right" width="11%"><IMG id="ImageButton11" onclick="javascript:show(table_index,ImageButton11)" src="../Common/images/arrow_hide.gif"
    height="21"></td>
    </tr>
    </table>
    <table>
    <tr>
    <td vAlign="top" width="100%" colSpan="4">
    <table id="table_index" style="WIDTH: 839px" cellSpacing="0" cellPadding="0" width="839"
    border="0" runat="server">
    <tr>
    <td vAlign="top" align="left" width="100%" colSpan="2">
    <div style="WIDTH: 869px"><asp:table id="Table_Head" runat="server" Width="93%"></asp:table></div>
    <FONT face="宋体"></FONT>
    </td>
    </tr>
    <tr>
    <td vAlign="top" align="left" width="100%" colSpan="2">
    <div style="OVERFLOW: auto; WIDTH: 869px; HEIGHT: 300px"><asp:table id="Table_Main" runat="server" Width="95%"></asp:table></div>
    </td>
    </tr>
    <tr>
    <td align="left" colSpan="2" height="1"><FONT face="宋体"></FONT></td>
    </tr>
    </table>
    <FONT face="宋体"></FONT>
    </td>
    </tr>
    </table>调用的函数如下:
    <SCRIPT language="javascript">
    function show(tabid,imgid){
                           if(tabid.style.display!='none')
                                   {
                               imgid.src='../Common/images/arrow_show.gif';
                               tabid.style.display='none';
                           }
                           else
                                   {
                               imgid.src='../Common/images/arrow_hide.gif';
                               tabid.style.display='block';
                           }
    }
    </SCRIPT>
      

  8.   

    运行时,'ImageButton11'可以用,但点击'ImageButton10'时报“网页有错误”
      

  9.   


    <table style="WIDTH: 839px" cellSpacing="0" cellPadding="0" width="839" border="0">
    <tr>
    <td align="left" colSpan="4" height="5"><FONT face="宋体"></FONT></td>
    </tr>
    <tr>
    <td style="HEIGHT: 5px" align="left" width="9%"><FONT face="宋体">&nbsp;&nbsp;<asp:label id="Label_Line" runat="server">工艺路线</asp:label></FONT></td>
    <td style="HEIGHT: 5px" width="30%"><asp:dropdownlist id="DDL_Line" runat="server" Width="100%" AutoPostBack="True"></asp:dropdownlist></td>
    <td style="HEIGHT: 5px" width="50%"><FONT face="宋体"></FONT></td>
    <td style="HEIGHT: 5px" align="right" width="11%"><IMG id="ImageButton10" onclick="javascript:show('table_line','ImageButton10')" src="../Common/images/arrow_hide.gif"
    height="21"></td>
    </tr>
    <tr>
    <td align="left" colSpan="4" height="1"><FONT face="宋体"></FONT></td>
    </tr>
    <tr>
    <td></td>
    </tr>
    </table>
    <table>
    <tr>
    <td>
    <table id="table_line" style="WIDTH: 839px" cellSpacing="0" cellPadding="0" width="839"
    border="0" runat="server">
    <tr>
    <td align="left" colSpan="2" height="1"><FONT face="宋体"></FONT></td>
    </tr>
    <tr>
    <td vAlign="top" align="left" width="9%"><FONT face="宋体">&nbsp;&nbsp;<asp:label id="Label_LineCompose" runat="server">路线组成</asp:label></FONT></td>
    <td vAlign="top" align="left" width="91%" height="150"><FONT face="宋体"><iewc:treeview id="RTV_ProcCompose" runat="server" height="150" width="99.5%"></iewc:treeview></FONT></td>
    </tr>
    <tr>
    <td align="left" colSpan="2" height="1"><FONT face="宋体"></FONT></td>
    </tr>
    </table>
    </td>
    </tr>
    </table>

    <SCRIPT language="javascript">
    function show(tabid,imgid){
             if(document.getElementById(tabid).style.display!='none')
                 {
                 document.getElementById(imgid).src='../Common/images/arrow_show.gif';
                 document.getElementById(tabid).style.display='none';
             }
             else
                 {
                 document.getElementById(imgid).src='../Common/images/arrow_hide.gif';
                 document.getElementById(tabid).style.display='block';
             }
    }
    </SCRIPT>
      

  10.   

    现在成功了吗?show(table_index,ImageButton11)不能直接这样调用,这2个参数没有定义
      

  11.   

    net_lover(孟子E章),老大,还没有解决的
    show(table_index,ImageButton11)可以这样调用啊,都能实现
    但偏偏show(table_line,ImageButton10)却实现不了,真是郁闷呀