2017-07-15 10 views
0

正如標題所說無法讀取上的其他空的特性「風格」,錯誤是「不能讀取屬性的null‘風格’的Javascript:在divToHide

<body class="container"> 
    <div class="row img"> 
    <div class="col-lg-2"><img onclick="divToHide(q1);" class="poster" src="img/batman-begins.jpg"> 
     <div style="display: none;" id="q1">Batman Begins (2005) 
     <br> FSK: 12 Action, Adventure 16.06.2005 
     <br>After training with his mentor, Batman begins his fight to free crime-ridden Gotham City from the corruption that Scarecrow and the League of Shadows have cast upon it. 
     <br> Director: Christopher Nolan</div> 
    </div> 
    <div class="col-lg-2"><img onclick="divToHide(q2);" class="poster" src="img/x-men.jpg"> 
     <div style="display: none;" id="q2">X-Men (2000) 
     <br> FSK: 12 Action, Adventure, Sci-Fi 31.08.2000 
     <br>Two mutants come to a private academy for their kind whose resident superhero team must oppose a terrorist organization with similar powers. 
     <br> Director: Bryan Singer</div> 
    </div> 
    <div class="col-lg-2 last-Child" style="display: none;"></div> 
    </div> 
    <div class="row menu"> 
    <div class="col-lg-2 last-Child1" style="display: none;"></div> 
    </div> 
</body> 
<script type="text/javascript"> 
    function divToHide(id) { 
    var div = document.getElementById(id); 
    if (div.style.display == 'block') { 
     div.style.display = 'none'; 
    } else { 
     div.style.display = 'block'; 
    } 
    } 
</script> 

回答

1

變化的onclick =」 divToHide(Q1 );「to onclick =」divToHide('q1');「等等

+0

謝謝你,你是最棒的 – ihdusg