javascript - Facebook Dom Placeholder on Password -
facebook has "dom placeholder" on password field when logging on. when click on input password, placeholder disappears , allows me type password "masked".
is javascript related , how go on replicating script?
yes, can done via javascript, browsers support natively. placeholder
attribute html5 addition; browsers (such webkit-based browsers) support already.
example using jquery 1.4
<!-- work automatically browsers --> <input type="text" placeholder="enter text"> <!-- script browsers don't support natively --> <script type="text/javascript"> $.fn.placeholder = function(){ // quit if there's support html5 placeholder if (this[0] && 'placeholder' in document.createelement('input')) return; return .live('focusin',function(){ if ($(this).val() === $(this).attr('placeholder')) { $(this).val(''); } }).live('focusout',function(){ if ($(this).val() === ''){ $(this).val( $(this).attr('placeholder') ); }_ }); } $('input[placeholder]').placeholder(); </script>
note: code copied this pastie linked jquery 1.4 hawtness. haven't verified works across browsers. can find other javascript solutions on google if don't use jquery.
Comments
Post a Comment