HTML5 placeholder disappears on focus

前端 未结 6 874
广开言路
广开言路 2020-11-29 01:58

Is there a freely available jQuery plugin that changes placeholder behavior to match HTML5 spec?

Before Focus

6条回答
  •  伪装坚强ぢ
    2020-11-29 02:27

    How about something simple like this? On focus save out the placeholder attribute value and remove the attribute entirely; on blur, put the attribute back:

    $('input[type="text"]').focus( function(){
      $(this).attr("data-placeholder",$(this).attr('placeholder')).removeAttr("placeholder");
    });
    $('input[type="text"]').blur( function(){
      $(this).attr("placeholder",$(this).attr('data-placeholder'));
    });   
    

提交回复
热议问题