2017-10-08 20 views
0

工作的每件事情很好,但div.closed {display:none;}不工作。当我关闭div但书图像仍然显示正确的浮动。我正在尝试修复它,但当我关闭div时,它仍然显示为右侧。当我点击Murach的HTML5和CSS3或列表的任何其他标题时,我试图使其消失。这里是代码。我想让yu找出我犯错的地方,否则你也可能会发布更新。等待你的指导 代码在这里我无法消失图像后,我关闭div

<!DOCTYPE html> 
<html> 
<head><title>FAQs</title> 
<script> 
window.onload = function() { 
var faqs = document.getElementById("faqs"); 
var h2Elements = faqs.getElementsByTagName("h2"); 
var h2Node; 
for (var i = 0; i < h2Elements.length; i++) { 
h2Node = h2Elements[i]; 
// Attach event handler 
h2Node.onclick = function() { 
var h2 = this; // h2 is the current h2Node object 
if (h2.getAttribute("class") == "plus") 
h2.setAttribute("class", "minus"); 
else 
h2.setAttribute("class", "plus"); 
if (h2.nextElementSibling.getAttribute("class") == "closed") 
h2.nextElementSibling.setAttribute("class", "open"); 
else 
h2.nextElementSibling.setAttribute("class", "closed"); 
} 
} 
} 
</script> 
<script> 
function changeIt (file) { 
document.querySelector('.book-image img').setAttribute("src", file); 
} 
</script> 
<style> 
body { font-family: Verdana, Arial, sans-serif; width: 1280px; margin: 0 
auto; border: 3px solid blue; margin-top: 30px; } 
section { padding: 15px 25px; border: 2px solid green;} 
h1 {font-size: 150%;} 
h2 { font-size: 120%; padding: .25em 0 .25em 25px; cursor: pointer; } 
h2.plus { background: url(images/plus.png) no-repeat left center; } 
h2.minus { background: url(images/minus.png) no-repeat left center; } 
ul { padding-left: 45px; } 
li { padding-bottom: .25em; } 
p { padding-bottom: .25em; padding-left: 25px; } 
div.closed { img-display: none;} 
div.open { display: block;} 
.book-image img { float: right; width: 20%; } 
</style>  
</head> 
<body> 
<section id="faqs"> 
<div class="book-image"><img src="#"></div> 
<h1 style="color:Blue;">Murach products</h1> 
<h2 class="plus">Books for web developers</h2> 
<div class="closed"> 
<a href="#" id="1" onclick="changeIt('images/pic1_1.jpg'); return false;"> 
<p>Murach's HTML5 and CSS3</p></a> 
<a href="#" id="2" onclick="changeIt('images/pic1_2.jpg'); 
return false;"><p>Murach's javascripting and DOM scripting</p></a> 
<a href="#" id="3" onclick="changeIt('images/pic1_3.jpg'); return false;"> 
<p>Murach's PHP and MYSQL</p></a> 
<a href="#" id="4" onclick="changeIt('images/pic1_4.jpg');return false;"> 
<p>Murach's MYSQL</p></a> 
</div> 
<h2 class="plus">Books for Java developers</h2> 
<div class="closed"> 
<a href="#" id="1" onclick="changeIt('images/pic2_1.jpg'); return false;"> 
<p>Murach's Java Programming</p></a> 
<a href="#" id="2" onclick="changeIt('images/pic2_2.jpg'); return false;"> 
<p>Murach's Java Servlets and JSP</p></a> 
<a href="#" id="3" onclick="changeIt('images/pic2_3.jpg'); return false;"> 
<p>Murach's Oracle SQL and PL/SQL</p></a> 
</div> 
<h2 class="plus">Books for .Net developers</h2> 
<div class="closed"> 
<a href="#" id="1" onclick="changeIt('images/pic3_1.jpg'); return false;"> 
<p>C# 2010</p></a> 
<a href="#" id="2" onclick="changeIt('images/pic3_2.jpg'); return false;"> 
<p>ASP.NET for Web Programming with C# 2010</p></a> 
<a href="#" id="3" onclick="changeIt('images/pic3_3.jpg'); return false;"> 
<p>Visual Basic 2010</p></a> 
<a href="#" id="4" onclick="changeIt('images/pic3_4.jpg'); return false;"> 
<p>ASP.NET for Web Programming with VB 2010</p></a> 
<a href="#" id="4" onclick="changeIt('images/pic3_5.jpg'); return false;"> 
<p>SQL Server 2012</p></a> 
</div> 
</section> 
</body> 
</html> 

回答

0

你的代码已经

div.closed { img-display: none;} 

(IMG-显示犯规存在)

将其更改为

div.closed { display: none; } 

如果不工作,

div.closed { display: none !important; } 
+0

仍然无法正常工作。我是gona分享你与jsfidder的链接 –