2012-11-16 49 views
0

這裏是我的代碼:聚焦子元素,火災父元素模糊

<div tabindex="0" id="parent" style="margin-top:200px;margin-left:200px;background-color:black;height:100px;width:200px;"> 
    <input type="text" style="width:80px;margin:5px auto;display:none"> 
<div> 



$("#parent").blur(function() { 
    $(this).css("background-color", "blue").animate({ 
       marginLeft : '+=50' 
      }, 400); 
    $("#parent>input").css("display", "none"); 
    }); 

    $("#parent>input").focus(function() { 
    $(this).css("display", "block"); 
    }); 
    $("#parent>input").blur(function() { 
    $(this).css("display", "none"); 
    }); 
    $("#parent>input").keyup(function(e) { 
    if (e.which === 13) { 
     console.log("enter"); 
    } 
    }); 

着眼於輸入,導致模糊對父DIV被解僱,它導致的div消失,所以用戶無法在文本框內輸入任何文本!

http://jsfiddle.net/z7Erv/10/

什麼想法?

+0

什麼是完整的工作流程?我知道你想要什麼,但你目前的解決方案是不好的。所以需要知道所有的步驟,以便我可以完成適當的實施。 – mrtsherman

+0

我試圖模仿谷歌文檔/單詞評論插件,所以當用戶關注評論區域時,我需要將評論div移動(動畫)到左邊(靠近主文檔)並使文本框可見,然後讓他們要輸入一些評論和模糊,將div(評論區域)向右移動,並使文本框再次隱藏! –

+0

同樣的問題在這裏http://stackoverflow.com/questions/18259754/ie-click-on-child-does-not-focus-parent-parent-has-tabindex-0 – Ouadie

回答

2

,如果這個問題已經過時不知道 - 這是也許你想幹什麼?: https://jsfiddle.net/1280pn4n/1/

$('#parent').bind('focusin focusout', function() { 
    $(this).toggleClass('showup'); 
}); 

我有同樣的問題,並從Keltex答案幫助(使用的focusIn /事件的內容,而不是什麼的onfocus /模糊):

jQuery figuring out if parent has lost 'focus'

+0

你的答案幫了我,我一直在嘗試在div和ul上聚焦/模糊數小時。謝謝! – Larrydx