2016-07-15 2 views
1

나는 입력 된 html 값 앞에있는 함수가 있습니다. 문제는 그 값이 앞에 붙으면 모바일 키보드를 숨기고 싶다는 것입니다. 현재 나는 이것을하기 위해 blur()를 사용하고 있습니다 만 누군가가 값을 입력 할 수 있기 전에 모든 것을 숨겨서 제가 앞에 붙일 수 있습니다.jQuery를 사용하여 모바일 키보드를 숨기는 방법

이 함수는 버튼을 처음 눌렀을 때 동적으로 추가 된 클래스를 사용하므로 .on 클릭이 본문에있는 이유는 무엇입니까?

어떤 권장 사항이 있습니까? 내가 제대로 이해 해요 경우

function addClassForReply() { 
    $(".reply-btn").click(function(e) { 
     $(".reply-btn").addClass('send-message'); 
    }); 
    } 
addClassForReply(); 

function replyMessage() { 
    $("body").on('click', '.send-message', function(e){ 
     var replyMessage = $(".message-reply textarea").val(); 
     $(".message-reply").prepend(replyMessage); 
     $(".message-reply textarea").fadeOut().blur(); 
    }); 
    } 
replyMessage(); 

HTML은

<div class="message-reply"> 
    <textarea placeholder="Reply to Linnie"></textarea> 
</div> 

<div class="message-mobile-footer"> 
    <div class="nm-body"> 
    <div class="row"> 
     <!-- THIS IS WHERE THE CLASS GETS ADDED --> 
     <a class="btn default reply-btn">Reply</a> 
    </div> 
    </div> 
</div> 
+0

동적 요소의 경우 일반적으로'$ (document) .on'을 사용합니다. 차이점이 있는지 확실하지 않습니다. 전자가 'body'를 사용하지 못하도록 함 – Adjit

+0

실제로 문서를 시도했지만 어떤 이유로 작동하지 않습니다. – luke

+0

'message-reply'를 클릭하면 텍스트를 입력 할 수 없으므로'.send-message' 이벤트가 발생합니다. – Adjit

답변

1

, 당신은, 음, 당신이 사용할 수있는 대신 요소 .blur()의 모바일 키보드를 축소 할 뭔가가 필요

$("document").focus(); 

JSFiddle

관련 문제