我可能會在這裏失去彈珠,但我覺得這是非常簡單的JavaScript。出於某種原因,#recipes元素上的第一個addEventListener調用會觸發第一個和第二個事件處理程序中的語句,而第二個事件處理程序根本不起作用。兩個不同元素上的兩個addEventListener函數
var recipes = document.getElementById('recipes');
var close_heart = document.getElementById('close_heart');
var recipes_container = document.getElementById('recipes_container');
recipes.addEventListener('click', function(){
recipes_container.style.display = 'block';
});
close_heart.addEventListener('click', function(){
recipes_container.style.display = 'none';
});
<div id="recipes"><a href="#" id="close_heart"><span>Recipes</span></a></div>
<section id="recipes_container"><a href="#" class="fa fa-gittip"></a>
<h1>Real Mac & Cheese</h1>
<ul>
<li>Rule #1 – Use only real cheese (no powdered cheese ever!)</li>
<li>Rule #2 – Use multiple cheese-type varieties (ex: sharp cheddar, monterey jack, bleu)</li>
<li>Rule #3 – Choose an extra protein like bacon to liven it up!</li>
</ul>
</section>
</div>
謝謝。
請分享html – RahulB
我太尷尬了。 –