问题
The input can set the placeholder, but if the user focus on that input , the place holder is disappear, how can I dismiss the placeholder, util the user start type at less one char?? Thank you.
回答1:
Not with the default behavior. However, You could it do by adding some JS into the 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 a limitation where if a user pastes some text into the box it won't clear, but you could easily fix that by binding to the change event as well. This is just a demo
回答2:
Using the placeholder
attribute, you can't.
来源:https://stackoverflow.com/questions/5839573/can-i-preserve-placeholder-if-the-user-select-the-input-text-and-the-input-valu