其次是HTML DOM:
<div class="opt">
Options
<div class="panel">
<h3>i am in panel!!</h3>
</div>
</div>
當我在.opt
點擊它會顯示.panel
內容,但後來我需要觸發另一個事件隱藏點擊.opt
元素外部的.panel
。
的jQuery:
$('.opt').click(function(){
var $this = $(this);
$this.find('.panel').fadeIn();
$this.blur(function(){
$this.find('.panel').fadeOut();
alert('i am from blur');
});
});
下面是一個演示JsFiddle
但blur()
法不執行,我在做什麼錯在這裏技術上?
看http://stackoverflow.com/questions/1985292/problem-with-jquery-blur-event-on-div-element。我用一個tab索引屬性嘗試了你的代碼,它可以工作。 – jnoreiga
看這樣的: [http://stackoverflow.com/questions/1985292/problem-with-jquery-blur-event-on-div-element][1] [1]: http://stackoverflow.com/questions/1985292/problem-with-jquery-blur-event-on-div-element – DZanella
我注意到它適用於'mouseleave'而不是模糊,但是,它不聽點擊 – rakibtg