채택완료

if문 focus들어갓을때 나왔을떄

2019-02-13 (수) 10:53:57 4,321

if $("[type=text]").focus(function() { 

        $(this).prev().animate({opacity:1}, 700);
        $(this).attr('placeholder', ' ');
        $(this).css('border-bottom', '2px solid #0e7bfc');

    } else {

    }
});

포커스가가면 저위에 스타일이먹고 나오면 원상복구 되는 걸하고싶은데..

우선 이프문 부터 안먹히는데 방법좀알려주세요..

|

답변 3개 / 댓글 2개

채택된 답변
+20 포인트
2019-02-13 (수) 11:08:12

$('[type=text]').on('focus',function(){ 

$(this).prev().animate({opacity:1}, 700); 
$(this).attr('placeholder', ' '); 
$(this).css('border-bottom', '2px solid #0e7bfc'); 

}).on('focusout',function(){

$(this).prev().animate({opacity:0}, 200); 
$(this).attr('placeholder'); 
$(this).css('border-bottom', '1px solid #b2b2b2'); 

})
; 

2019-02-13 (수) 11:02:52

$('[type=text]').on('focusin',function(){ //포커스 인

});

$('[type=text]').on('focusout',function(){ //포커스 아웃

});

안에 각 상태일때 원하시는 작업을 넣으시면 될거 같습니다.

답변에 대한 댓글 1개

2019-02-13 (수) 11:08:26
이프분으로 제어가능한방법은 없을까요?
2019-02-13 (수) 10:55:14

$('[type=text]').on('focus',function(){

});

답변에 대한 댓글 1개

2019-02-13 (수) 11:03:50
$('[type=text]').on('focus',function(){
if($(this).focus){
$(this).prev().animate({opacity:1}, 700);
$(this).attr('placeholder', ' ');
$(this).css('border-bottom', '2px solid #0e7bfc');
}else{
$(this).prev().animate({opacity:0}, 200);
$(this).attr('placeholder');
$(this).css('border-bottom', '1px solid #b2b2b2');
}
});


이러면 포커스가 빠졋을때는 반응이 없습니다..

답변을 작성하려면 로그인이 필요합니다.