注册 登录
编程论坛 ASP技术论坛

简单问题 select 表格隐藏

usajx 发布于 2010-11-25 16:38, 846 次点击
<script type="text/javascript">
function cht(){
var tt=document.getElementById("TAction").value;
switch(tt){
case "0":
tb1.style.display="none";
tb2.style.display="none";
break;
case "1":
tb1.style.display="";
tb2.style.display="none";
break;
case "2":
tb1.style.display="";
tb2.style.display="";
break;
}
}
</script>

<table>
<tr><td><input name="name3" type=text id='name3'>
</td></tr>
<tr><td>
<select id='TAction' name="TAction" size="1" onchange="cht()">
<option value='0' <%if rs("TAction")=0 then response.write "selected"%>>0</option>
<option value='1' <%if rs("TAction")=1 then response.write "selected"%>>1</option>
<option value='2' <%if rs("TAction")=2 then response.write "selected"%>>2</option>
</select>
</td></tr>
<tr id="tb1" style="display:none;"><td> <input name="name1" type=text id='name1'> </td></tr>
<tr id="tb2" style="display:none;"><td><input name="name1" type=text id='name1'></td></tr>
</table>

打开页面转过来无论TAction的值是几,所有表格都是隐藏的
请问如何让这个页面打开直接显示相应的表格数,然后仍然可以根据相应的选择显示或隐藏表格。


3 回复
#2
筱晓绾2010-11-25 16:42
加载的时候,将需要显示的表格的display属性设为block.
#3
usajx2010-11-25 16:44
回复 2楼 筱晓绾
需要显示的表格数量不确定,
可不可以根据数据库中读取的数值直接显示。
#4
dzt00012010-11-25 18:11
程序代码:
<%
n
=10    '可以改为从数据库中获取
%>
<script type="text/javascript">
function cht(){
var tt=parseInt(document.getElementById("TAction").value);

for (var i=1; i<<%=n+1%>; i++){
   
if (i<tt+1) {
        document.getElementById(
"tb"+i).style.display="";
    }
else{
        document.getElementById(
"tb"+i).style.display="none";
    }
}

}
</script>

<table>
<tr><td><input name="name0" type=text id="name0">
</td></tr>
<tr><td>
<select id='TAction' name="TAction" size="1" onchange="cht()">
<% for i=0 to n %>
<option value="<%=i%>"><%=i%></option>   
<% next %>
</select>
</td></tr>
<% for i=1 to n %>
<tr id="tb<%=i%>" style="display:;"><td><%=i%>. <input name="name<%=i%>" type=text id="name<%=i%>"></td></tr>
<% next %>
</table>
1