How do I auto-hide placeholder text upon focus using css or jquery?

后端 未结 26 1837
长情又很酷
长情又很酷 2020-11-28 00:39

This is done automatically for every browser except Chrome.

I\'m guessing I have to specifically target Chrome.

Any solutio

26条回答
  •  盖世英雄少女心
    2020-11-28 01:21

    2018 > JQUERY v.3.3 SOLUTION: Working globaly for all input, textarea with placeholder.

     $(function(){
         $('input, textarea').on('focus', function(){
            if($(this).attr('placeholder')){
               window.oldph = $(this).attr('placeholder');
                $(this).attr('placeholder', ' ');
            };
         });
    
         $('input, textarea').on('blur', function(){
           if($(this).attr('placeholder')){
                $(this).attr('placeholder', window.oldph);
             };
         }); 
    });
    

提交回复
热议问题