因此,我编写了一个简单的流程图,可能我做错了,但是在设计上,它似乎可以按照我的方式工作。在代码方面,我似乎做错了什么,它应该显示4个元素,即h1和3个div来显示您的选项,当您单击“是”或“否”时,它将显示与您的内容相关的其他元素这里的选择是我的标记,我已经通过http://validator.w3.org/运行了它,它说很好。
在第150行,它说我在Dreamweaver中有语法错误(我使用的程序)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Untitled Document</title>
<style>
body{background-color:#999}
p{color:#0CF}
h1{
color:#03C;
text-align:center;
}
#q1{
position:absolute;
left:293px;
top:41px;
border:thin black solid;
background-color:#9CF;
width: 531px;
height: 72px;
font-size:64px
}
#q2{
position:absolute;
left:424px;
top:257px;
border:thin black solid;
background-color:#9CF;
width: 62px;
height: 54px;
font-size:48px;
}
#q3{
position:absolute;
left:633px;
top:405px;
border:thin black solid;
background-color:#9CF;
width: 186px;
height: 39px;
font-size:32px
}
#q4{
position:absolute;
left:494px;
top:145px;
border:thin black solid;
background-color:#9CF;
width: 100px;
height: 165px;
font-size:36px
}
#q5{
position:absolute;
left:633px;
top:255px;
border:thin black solid;
background-color:#9CF;
width: 74px;
height: 55px;
font-size:48px;
}
#q6{
position:absolute;
left:573px;
top:407px;
border:thin black solid;
background-color:#9CF;
width: 50px;
height: 39px;
font-size: 36px
}
#q7{
position:absolute;
left:240px;
top:404px;
border:thin black solid;
background-color:#9CF;
width: 246px;
height: 41px;
font-size:36px;
}
#q8{
position:absolute;
left:671px;
top:317px;
border:thin black solid;
background-color:#000;
width: 2px;
height: 82px;
}
#q11{
position:absolute;
left:854px;
top:453px;
border:thin black solid;
background-color:#000;
width: 5px;
height: 59px;
font-size:36px;
}
#q12{
position:absolute;
left:449px;
top:319px;
border:thin black solid;
background-color:#000;
width: 4px;
height: 78px;
font-size:36px;
}
#q13{
position:absolute;
left:551px;
top:519px;
border:thin black solid;
background-color:#9CF;
width: 371px;
height: 44px;
font-size:36px;
}
#q14{
position:absolute;
left:826px;
top:401px;
border:thin black solid;
background-color:#9CF;
width: 61px;
height: 44px;
font-size:36px;
}
#q15{
position:absolute;
left:602px;
top:454px;
border:thin black solid;
background-color:#000;
width: 5px;
height: 57px;
font-size:36px;
}
.hidden{
visibility:hidden
}
</style>
<script>
function show (x) {
var a=document.getElementById(x)
a.style.visiblity.visible
</script>
</head>
<!-- ADD IDS TO HIDDEN CLASSES, MAKE FUNCTION TO SHOW THEM ON NON-HIDDEN ELEMENTS -->
<body>
<div id="q1">Should You Worry?</div>
<div id="q2" onClick="show('q7')">No</div>
<div id="q3" class="hidden" >Can you fix it?</div>
<div id="q4"> Do you have a problem?</div>
<div id="q5" onClick="show('q3,q6,q14')">Yes</div>
<div id="q6" class="hidden" onClick="show('q13')">No</div>
<div id="q7" class="hidden">Then don't worry</div>
<div id="q8" class="hidden"></div>
<div id="q11" class="hidden"></div>
<div id="q12" class="hidden"></div>
<div id="q13" class="hidden">Then don't worry about it!</div>
<div id="q14" class="hidden" onClick="show('q13')">Yes</div>
<div id="q15" class="hidden"></div>
</body>
</html>
最佳答案
show()必须像这样:
function show(x) {
var a=document.getElementById(x);
a.style.visibility = "visible";
}
您必须为
visibility
设置一个值,该值可以为以下[1]:隐
可见
坍方
继承
使用
a.style.visibility.visible
时,您尝试访问的“可见性”中的“可见”属性不存在。有关样式属性的内容的完整信息,请打开firebug / devtools并在控制台上编写document.getElementById('xxx').style;
(其中xxx是元素的ID),该命令将列出样式内的所有属性(它们全部显示为字符串)。有关更多信息,请阅读MDN HTMLElement.style
您应该注意的一件事是
show('q3,q6,q14')
尝试使用不存在的document.getElementById('q3,q6,q14')
(查找类似<element id="q3,q6,q14">
的东西)。为此用途:<div id="q5" onClick="show('q3');show('q6');show('q14');">Yes</div>
或者,您可以将
show()
更改为较新的名称(但以does not support IE7为代价):function show(x) {
var a=document.querySelectorAll(x);
for(var i=0;i<a.length;i++){
a[i].style.visibility = "visible";
}
}
并与CSS选择器一起使用,然后接受
,
:<div id="q5" onClick="show('#q3,#q6,#q14');">Yes</div>
如果您需要支持下面的IE7,Sergio's answer就足够了。