简体   繁体   English

单击li时未触发jQuery的.blur()

[英]jQuery's .blur() not fired when clicking on li

So we have a <ul> which contains several <li> s, and a <textarea> . 因此,我们有一个包含多个<li><ul>和一个<textarea> The <textarea> has a .blur() event handler which works as expected when clicking outside. <textarea>具有一个.blur()事件处理程序,可以在外部单击时按预期方式工作。 However, if I set focus on the <textarea> , then click on one of the <li> s to make the <textarea> lose focus, .blur() is not fired. 但是,如果将焦点放在<textarea> ,然后单击<li>以使<textarea>失去焦点,则不会触发.blur() Any idea why this happens and how to make it work? 知道为什么会发生这种情况以及如何使其起作用吗?

Code: 码:

$("textarea").blur(function(e) {
// Do something
});

By the way, the <li> has no .click() handler. 顺便说一句, <li>没有.click()处理函数。

Environment: Mac OS X 10.9, Chrome 46. 环境:Mac OS X 10.9,Chrome 46。

Only a few browsers support/detect the blur event on non-form elements. 只有少数浏览器支持/检测非表单元素上的模糊事件。 But, of course, you can always trigger an event by yourself or as a reaction. 但是,当然,您总是可以自己触发或作为响应触发事件。 See here: jsfiddle 看到这里: jsfiddle

<textarea></textarea>
<div>here is the div</div>
<strong>here is the strong</strong>

$('textarea').blur(function() {
    alert('ta blur');
});
$('div').blur(function() {
    alert('div blur');
});
$('strong').blur(function() {
    alert('strong blur');
});

$(document).ready(function() {
    $('strong').trigger('blur');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM