<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<script LANGUAGE="JavaScript">
function showOrHide(value) {
if (value==0) {
if (document.layers)
document.layers["layer1"].visibility='hide';
else
document.all["layer1"].style.visibility='hidden';
}
else if (value==1) {
if (document.layers)
document.layers["layer1"].visibility='show';
else
document.all["layer1"].style.visibility='visible';
}
}
</script>
<form NAME="form1">
<input TYPE="button" VALUE="显 示" onClick="showOrHide(1);">
<input TYPE="button" VALUE="关 闭" onClick="showOrHide(0);">
</form>
<div ID="layer1" style="position:absolute; LEFT:169px; TOP:46px; background-color:#BFE3C0; width:120;height:100; visibility:hidden">
<font color=blue><b>欢迎你的光临!</b></font><br>
<font color="#7E059C">这个脚本很有用的,具体的你自己想想</font></div>
</body>
</html>
这样写的话可以正常显示和隐藏层,但是如果再加一个层的话打开页面就会说“语法错误”,点了"显 示"后会说“缺少对像”,请问是为什么?
加了一个层后的源码是这样写的:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<script LANGUAGE="JavaScript">
function showOrHide(value) {
if (value==0) {
if (document.layers)
document.layers["layer1"].visibility='hide';
document.layers["layer2"].visibility='hide';
else
document.all["layer1"].style.visibility='hidden';
document.all["layer2"].style.visibility='hidden';
}
else if (value==1) {
if (document.layers)
document.layers["layer1"].visibility='show';
document.layers["layer2"].visibility='show';
else
document.all["layer1"].style.visibility='visible';
document.all["layer2"].style.visibility='visible';
}
}
</script>
<form NAME="form1">
<input TYPE="button" VALUE="显 示" onClick="showOrHide(1);">
<input TYPE="button" VALUE="关 闭" onClick="showOrHide(0);">
</form>
<div ID="layer1" style="position:absolute; LEFT:169px; TOP:46px; background-color:#BFE3C0; width:120;height:100; visibility:hidden">
<font color=blue><b>欢迎你的光临!</b></font><br>
<font color="#7E059C">这个脚本很有用的,具体的你自己想想</font></div>
<div ID="layer2" style="position:absolute; LEFT:365px; TOP:45px; background-color:#BFE3C0; width:120;height:100; visibility:hidden">
<font color=blue><b>欢迎你的光临!</b></font><br>
<font color="#7E059C">这个脚本很有用的,具体的你自己想想</font></div>
</body>
</html>
[此贴子已经被作者于2005-12-7 13:45:40编辑过]