我希望当使用者点击元素区域之外时,
.shell-pop
类的<div>
元素被关闭。但是当前实现似乎不会触发任何操作,也没有任何日志或提示弹窗。我已经查看了相关文档,似乎一切都没问题?
jQuery
$('document').ready(function () {
updateCart();
$(".shell").click(function (e) {
e.preventDefault();
$(".shell-pop").fadeIn(300, function () { $(this).focus(); });
});
$(".shell-pop").on('blur', function () {
$(this).fadeOut(300);
window.alert("work");
console.log("works");
});
});
HTML
<div class="options-area">
<div class="options-popup shell-pop">
<div class="swatches">
<div class="colors-shell colors" id="green">
<p class="prices-for-swatch">$14.23</p>
</div>
<div class="colors-shell colors" id="pink">
<p class="prices-for-swatch">$7.23</p>
</div>
<div class="colors-shell colors" id="blue">
<p class="prices-for-swatch">$11.25</p>
</div>
<div class="colors-shell colors" id="orange">
<p class="prices-for-swatch">$10.23</p>
</div>
<div class="colors-shell colors" id="default-shell">
<p class="prices-for-swatch">FREE</p>
</div>
<div class="colors-shell colors" id="exit">
<img src="img/Silhouette-x.png" class="x-logo" alt="exit" />
<p class="closeit">CLOSE</p>
</div>
<div class="shell square">
<img src="img/controllers.png" class="item-icon" alt="controller-piece">
<p class="name-of-item">Shell</p>
<p id="shell_Price1" class="items-price">0.00</p>
</div>
.shell-pop
?如果元素不是输入元素,则模糊事件不会被触发。 - Rajaprabhu Aravindasamyblur()
在 div 上不起作用,我认为。请参见这里:https://dev59.com/jnM_5IYBdhLWcg3wt1k0#1259769 - Sam FenWindow
和Element
- 因此,div
元素是blur
事件的有效目标(在我刚刚在Firefox中运行的测试中它可以工作)。https://www.w3.org/TR/DOM-Level-3-Events/#event-type-blur - Fenton