JavaScript:DIV . ID的用法。哪位有帮我看看?

afeisky 2003-06-29 03:30:06
<html>
<head>
<script language="javascript">

function show(ok) //????
{
for (i=0;i<3;i++) {
document.anchors[i].style.display="none";
}
document.all(ok).style.display="";
}

function closeall()
{
for (i=0;i<6;i++) {
document.anchors[i].style.display="none"; //???
}

}

function open()
{
for (i=0;i<6;i++) {
document.anchors[i].style.display="none"; //???
}

}

</script>
</head>

<body>
<DIV id="layer1">层1</DIV>
<DIV id="layer2">层2</DIV>
<DIV id="layer3">层3</DIV>
<DIV id="layer4">层4</DIV>
<DIV id="layer5">层5</DIV>
<DIV id="layer6">层6</DIV>
<DIV id="ok" name="kkk">上面的...</DIV>
<br>
<input type=button value="打开或关闭层3" onClick="show(layer3);">
<input type=button value="关闭所有的层" onClick="closeall();">
<input type=button value="打开层3并关闭其它所有的层" onClick="open(layer3);">
</body>
</html>

请问上面的show,closeall,open三个函数怎么写?
谢谢大虾们。
...全文
431 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
afeisky 2003-06-29
  • 打赏
  • 举报
回复
高手们,佩服!!!
给分了。

谢谢各位,好样的!!!
seabell 2003-06-29
  • 打赏
  • 举报
回复
<html>
<head>
<script language="javascript">

function show(ok) //????
{
document.all(ok).style.display=document.all(ok).style.display==""?"none":"";
}

function closeall()
{
for (i=1;i<7;i++) {
document.all("layer"+i).style.display="none"; //???
}

}

function myopen(ok2)
{
for (i=1;i<7;i++) {
document.all("layer"+i).style.display="none"; //???
}
document.all(ok2).style.display="";
}

</script>
</head>

<body>
<DIV id="layer1">层1</DIV>
<DIV id="layer2">层2</DIV>
<DIV id="layer3">层3</DIV>
<DIV id="layer4">层4</DIV>
<DIV id="layer5">层5</DIV>
<DIV id="layer6">层6</DIV>
<DIV id="ok" name="kkk">上面的...</DIV>
<br>
<input type=button value="打开或关闭层3" onClick="show('layer3');">
<input type=button value="关闭所有的层" onClick="closeall();">
<input type=button value="打开层3并关闭其它所有的层" onClick="myopen('layer3');">
</body>
</html>
Reker熊 2003-06-29
  • 打赏
  • 举报
回复
<script language="javascript">

function show(ok)
{
eval(document.all(ok)).style.display=(eval(document.all(ok)).style.display=="none")?"":"none";
}

function closeall()
{
for (i=1;i<=6;i++) {
document.all("layer"+i).style.display="none";
}

}
</script>
<DIV id="layer1">层1</DIV>
<DIV id="layer2">层2</DIV>
<DIV id="layer3">层3</DIV>
<DIV id="layer4">层4</DIV>
<DIV id="layer5">层5</DIV>
<DIV id="layer6">层6</DIV>
<DIV id="ok" name="kkk">上面的...</DIV>
<br>
<input type=button value="打开或关闭层3" onClick="show('layer3');">
<input type=button value="关闭所有的层" onClick="closeall();">
<input type=button value="打开层3并关闭其它所有的层" onClick="closeall();show('layer3')">
fason 2003-06-29
  • 打赏
  • 举报
回复
try like this:
<script language="JavaScript">
<!--
function show(flag){
var c=document.getElementById("myid").childNodes
for(i=0;i<c.length;i++)c[i].style.display=flag
}
//-->
</script>
<DIV id="myid">
<table border="1" cellpadding="0" cellspacing="0" width="100%" > <tr> <td>1</td> </tr></table>
<table border="1" cellpadding="0" cellspacing="0" width="100%" > <tr> <td>2</td> </tr></table>
<table border="1" cellpadding="0" cellspacing="0" width="100%" > <tr> <td>3</td> </tr></table>
<table border="1" cellpadding="0" cellspacing="0" width="100%" > <tr> <td>4</td> </tr></table>
<table border="1" cellpadding="0" cellspacing="0" width="100%" > <tr> <td>5</td> </tr></table>
</DIV>
<input type=button value="展开所有table" onclick="show('block')">
<input type=button value="关闭所有table" onclick="show('none')">
afeisky 2003-06-29
  • 打赏
  • 举报
回复
这样吧,下面的例子:
<DIV id="myid">
<table border="1" cellpadding="0" cellspacing="0" width="100%" > <tr> <td>1</td> </tr></table>
<table border="1" cellpadding="0" cellspacing="0" width="100%" > <tr> <td>2</td> </tr></table>
<table border="1" cellpadding="0" cellspacing="0" width="100%" > <tr> <td>3</td> </tr></table>
<table border="1" cellpadding="0" cellspacing="0" width="100%" > <tr> <td>4</td> </tr></table>
<table border="1" cellpadding="0" cellspacing="0" width="100%" > <tr> <td>5</td> </tr></table>

</DIV>
<input type=button value="展开所有table" onclick="show('show')">
<input type=button value="关闭所有table" onclick="show('hidden')">

请问,这个show函数怎么写?
紫郢剑侠 2003-06-29
  • 打赏
  • 举报
回复
可能要用<layer>来实现。

87,907

社区成员

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

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