我有以下脚本来下拉一个 div。正确的是,当我在 div 外部单击或选择另一个 div 向下时,已经滴下来的 div 正在向上。
但是当我点击 div 中的任何内容时,它不应该上升吗?
Javascript:
$(document).ready(function() {
$('#favorite_holder').click(function(e) {
$('#favorite_container').slideToggle("fast");
$('#account_container').slideUp("fast");
$('#cart_container').slideUp("fast");
e.stopPropagation();
});
$('#account_holder').click(function(e) {
$('#account_container').slideToggle("fast");
$('#favorite_container').slideUp("fast");
$('#cart_container').slideUp("fast");
e.stopPropagation();
});
$('#cart_holder').click(function(e) {
$('#cart_container').slideToggle("fast");
$('#favorite_container').slideUp("fast");
$('#account_container').slideUp("fast");
e.stopPropagation();
});
$(document).click(function(){
$('#favorite_container, #account_container, #cart_container').slideUp("fast");
});
});
HTML:
<div id="favorite_holder">
<span class="price">click here</span>
</div>
<div id="favorite_container" style="display: none;">
content here...
</div>
<div id="account_holder">
<span class="price">click here</span>
</div>
<div id="account_container" style="display: none;">
content here two ...
</div>
<div id="cart_holder">
<span class="price">click here</span>
</div>
<div id="cart_container" style="display: none;">
<form>
First name: <input type="text" name="firstname"><br>
Last name: <input type="text" name="lastname">
</form>
</div>