javascript - Can I preserve placeholder if the user select the input text, and the input value is empty string? -


the input can set placeholder, if user focus on input , place holder disappear, how can dismiss placeholder, util user start type @ less 1 char?? thank you.

not default behavior. however, adding js mix

live fiddle : http://jsfiddle.net/jomanlk/gpbhx/

<input type='text' class='placeholder' data-title='hello'>  $('.placeholder').each(function(){     $(this).data('placeholder', $(this).attr('data-title'));     $(this).val($(this).attr('data-title')); });  $('.placeholder').live('keydown', function(){     if ($(this).val() == $(this).data('placeholder')) {         $(this).val('');              }  });  $('.placeholder').live('blur', function(){     if ($(this).val().trim() == '') {         $(this).val($(this).data('placeholder'));     } }); 

note : there's limitation if user pastes text box won't clear, fix binding change event well. demo


Comments