jQuery focusout在输出元素退出时不触发 [英] jQuery focusout not triggering on exit of input element
本文介绍了jQuery focusout在输出元素退出时不触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
无论我在哪里点击文档,我都想发布焦点事件。但是,我使用的是可排序列表,其中每个可排序项目都包含textarea,单击可排序项目时不会触发focusout事件。可拖动项目也是如此。我创建了一个jsfiddle来展示这个问题:
I'd like to fire the focusout event no matter where I click on the document. However i'm using a sortable list which each sortable item contains a textarea, the focusout event isn't fired when clicking on the sortable items. The same occurs for draggable items. I have created a jsfiddle to showcase this issue:
单击textarea并尝试单击蓝色矩形内的任何位置:
在Google Chrome中测试
http://jsfiddle.net/RWJhs/
Click on the textarea and attempt to click anywhere within the blue rectangle: Tested in Google Chrome http://jsfiddle.net/RWJhs/
有任何已知的解决方法吗?
JavaScript:
JavaScript:
$("textarea").focusout(function(){
alert("Do something");
});
$("#draggable").draggable();
HTML:
<div id="draggable">
<textarea></textarea>
</div>
推荐答案
你可以试试这个
$("textarea").focusout(function(){
alert("Do something");
}).click(function(e){
e.stopPropagation();
return true;
});
$("#draggable").draggable({
start: function( event, ui ) {
if( $('textarea:focus', this).length ){
$('textarea', this).focusout();
}
}
}).click(function(e){
if( $('textarea:focus', this).length ){
$('textarea', this).focusout();
}
});
这篇关于jQuery focusout在输出元素退出时不触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文