[英]jquery on blur but focus on the other one
我有一个情况,我有一个带有两个输入元素的隐藏div,它在默认情况下是隐藏的,并且仅当我将内容悬停时才显示,而当我悬停时才消失。 现在,我希望该div如果输入元素之一被聚焦而不会消失,而如果模糊则消失。 我已经解决了这一部分,直到,如果焦点从一个输入转移到另一个输入,div将消失,而我不希望它消失,因为其中一个输入仍在聚焦。
这是我的代码:
// code with the problem I think.
$('#inputText1, #inputText2').live("blur", function() {
if ($('#myDiv').is(":visible")) {
if (!$(this).hasClass("jqTransformInputWrapper_focus")) {
$('#myDiv').fadeOut("slow");
}
}
});
// hover to show and hide the div
$(".visibleDiv").hover(
function() {
$('#myDiv').fadeIn("slow");
},
function() {
if(!$(this).find(".jqTransformInputWrapper").hasClass("jqTransformInputWrapper_focus")) {
$('#myDiv').fadeOut("slow");
}
}
);
我的HTML:
<div class="visibleDiv">
hover me
<div id="myDiv">
<input name="inputText1" id="inputText1" type="text" />
<input name="inputText2" id="inputText2" type="text" />
</div>
</div>
顺便说一句,我正在使用jqTransform作为输入元素。
尝试这个,
// code with the problem I think.
$('#inputText1, #inputText2').live("blur", function() {
if ($('#myDiv').is(":visible")) {
if (!$(this).hasClass("jqTransformInputWrapper_focus")) {
$('#myDiv').fadeOut("slow");
}
}
}).live("focus",function(){
$('#myDiv').stop(true,true).show();
});
给一些类输入框并在其上应用jQuery
<div class="visibleDiv">
hover me
<div id="myDiv">
<input name="inputText1" id="inputText1" type="text" class="inputbox" />
<input name="inputText2" id="inputText2" type="text" class="inputbox"/>
</div>
</div>
// now this will work
$('.inputbox').live("blur", function() {
// u can also use this
// if($(this).parent().is(":visible") )
if ($('#myDiv').is(":visible")) {
if (!$(this).hasClass("jqTransformInputWrapper_focus")) {
$('#myDiv').fadeOut("slow");
}
}
});
注意:使用委托代替实时
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.