我寫的這個js + HTML/CSS http://jsfiddle.net/A1ex5andr/xpRrf/ Tt的工作,它應: 開/關上.advSearch .advSearch-btn
收盤.advSearch-control .canc
但我不能讓它關門,如果鼠標點擊任何地方出<div class="advSearch">
JS顯示/隱藏/關閉,如果出了格
HTML部分
<div class="advSearch">
<span class="advSearch-btn">Advanced Search</span>
<div class="advSearch-container">
<div class="col left">
<h3>Customer</h3>
<form action="">
<label><h4>First Name</h4> <input type="text"> </label>
<label><h4>Last Name</h4> <input type="text"> </label>
<label><h4>Email</h4> <input type="text"> </label>
<label><h4>Phone</h4> <input type="text"> </label>
</form>
</div>
<div class="col central">
<h3>Address</h3>
<form action="">
<label><h4>Adsress</h4> <input type="text"> </label>
<label><h4>City</h4> <input type="text"> </label>
<label><h4>State</h4> <input type="text"> </label>
<label><h4>Zip</h4> <input type="text"> </label>
</form>
</div>
<div class="col right">
<h3>Other</h3>
<form action="">
<label><h4>Policy</h4> <input type="text"> </label>
<label><h4>App ID</h4> <input type="text"> </label>
<label><h4>Quote</h4> <input type="text"> </label>
<label><h4></h4> <input type="text"> </label>
</form>
</div>
<div class="advSearch-control">
<button class="canc">Cancel</button>
<button class="srch">Search</button>
</div>
</div>
</div>
JS的作品
的名我試圖盡收在鼠標點擊出OUF: (在運行的代碼註釋)
$(document).click(function() {
if (container.is(":visible")) {
container.fadeOut(300);
} else {
e.stopPropagation();
console.log('its stoped');
}
});
或
$(document).click(function(event) {
if ($(event.target).parents().index(container) == -1) {
if (container.is(":visible")) {
container.hide()
}
}
})
的問題是什麼我做錯了嗎? 預先感謝您。
取消註釋第一個工作正常,它淡出開放的div。究竟是什麼問題? – StephenRios
與此處同樣的問題可能,聽起來類似? http://stackoverflow.com/questions/1403615/use-jquery-to-hide-a-div-when-the-user-clicks-outside-of-it –
他想關閉高級搜索屏幕的問題,如果他點擊該屏幕之外。 –