关于用SCRIPT函数实现折叠区域的问题

henfeideshuita 2005-06-13 09:53:45
我用的是.net开发平台,后台代码用的是c#。
我用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'分别表示什么意思?
...全文
95 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
myhyli 2005-06-13
  • 打赏
  • 举报
回复
var b = tab.currentStyle.display=="none";

你是不是用了class来设置默认的折叠状态?
henfeideshuita 2005-06-13
  • 打赏
  • 举报
回复
主要的问题还是:如果让区域默认展开,则执行正确;如果收缩,则不行。
到底是因为什么原因啊?
郁闷
henfeideshuita 2005-06-13
  • 打赏
  • 举报
回复
还是不行,点“ImageButton10”没有反映,连图片都不变;点“ImageButton11”图片变,但动态表格看不到了
henfeideshuita 2005-06-13
  • 打赏
  • 举报
回复
老大,先别走,等我再试一下
孟子E章 2005-06-13
  • 打赏
  • 举报
回复
meizz手误
应该这样

var b = tab.style.display=="none";
henfeideshuita 2005-06-13
  • 打赏
  • 举报
回复
图片可以显示,点击时报网页有错误
上述代码仅以ImageButton11为例
henfeideshuita 2005-06-13
  • 打赏
  • 举报
回复
完整代码如下,请高手指点,非常感激
<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="宋体">  <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)
{
var img = document.getElementById(imgid);
var tab = document.getElementById(tabid);
if(tab && img)
{
var b = tabid.style.display=="none";
img.src = b ? '../Common/images/arrow_hide.gif' : '../Common/images/arrow_show.gif';
tab.style.display = b ? "block" : "none";
}
}
</SCRIPT>
henfeideshuita 2005-06-13
  • 打赏
  • 举报
回复
meizz(梅花雪),你好,按你说的改了,那两个图片显示不了了,是不是哪里疏忽了?谢谢
meizz 2005-06-13
  • 打赏
  • 举报
回复
<SCRIPT LANGUAGE="JavaScript">
<!--
function show(tabid,imgid)
{
var img = document.getElementById(imgid);
var tab = document.getElementById(tabid);
if(tab && img)
{
var b = tabid.style.display=="none";
img.src = b ? '../Common/images/arrow_hide.gif' : '../Common/images/arrow_show.gif';
tab.style.display = b ? "block" : "none";
}
}
//-->
</SCRIPT>

onclick="javascript:show('table_index', 'ImageButton11')"
onclick="javascript:show('table_line', 'ImageButton10')"
henfeideshuita 2005-06-13
  • 打赏
  • 举报
回复
请大家帮忙啊
henfeideshuita 2005-06-13
  • 打赏
  • 举报
回复
运行时,'ImageButton11'可以用,但点击'ImageButton10'时报“网页有错误”

下面把我的完整代码贴出来,希望大家帮我分析:
报错的地方代码如下:
<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="宋体">  <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="宋体">  <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="宋体">  <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>

87,903

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧