1

これが私のコードです:

<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/

何か案が?

4

1 に答える 1

2

この質問が古いかどうかわからない - これはおそらくあなたがやりたいことですか?: https://jsfiddle.net/1280pn4n/1/

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

私はちょうど同じ問題を抱えていて、Keltex からの回答が役に立ちました (onfocus/blur の代わりに focusin/focusout を使用してください):

親が「フォーカス」を失ったかどうかを判断するjQuery

于 2015-07-21T23:44:33.137 に答える