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.