2011-02-18 42 views
0

我有一個情況,我有一個隱藏的div與默認隱藏的兩個輸入元素,只有當我懸停的東西,如果我徘徊了,消失回來顯示。現在我希望該div不會消失,如果其中一個輸入元素被聚焦,如果模糊消失。我已經解決了這部分,直到如果焦點從一個輸入轉移到另一個輸入,div將消失,我不希望它消失,因爲其中一個輸入仍然是焦點。jQuery的模糊,但專注於另一個

這裏是我的代碼:

// 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的輸入元素。

回答

1

試試這個,

// 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(); 
}); 
+0

這個工作很好,沒有`live'但只在FF上,IE上有這個工作嗎? – 2011-02-18 07:36:38

0

給一些類輸入框,並在該

<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"); 
     } 
    } 
}); 

注意申請的jQuery:使用delegate,而不是活

+1

其實是一樣的與我在做什麼。我的只是特定於兩個。 – 2011-02-18 06:54:19