Skip to content

Instantly share code, notes, and snippets.

@fdaciuk
Last active December 31, 2015 02:29
Show Gist options
  • Save fdaciuk/7921011 to your computer and use it in GitHub Desktop.
Save fdaciuk/7921011 to your computer and use it in GitHub Desktop.
Placeholder automático para vários campos usando jQuery
<input type="text" id="cp_bairro" />
<input type="text" id="cp_rua" />
<input type="text" id="cp_cep" />
(function( $, undefined ) {
'use strict';
var place = (function() {
return {
_input_info : [
{
id : 'cp_bairro',
text : 'Preencha o bairro'
},{
id : 'cp_rua',
text : 'Preencha a rua'
},{
id : 'cp_cep',
text : 'Preencha o CEP'
}
], // input_info
init : function() {
this.add_placeholder( this._input_info );
}, // init
add_placeholder : function( info ) {
var amount_inputs = info.length;
for( var i = amount_inputs; i--; ) {
$( '#' + info[i].id ).attr( 'placeholder', info[i].text );
}
} // add_placeholder
}; // return
})();
// DOM Ready
$(function() {
place.init();
});
})( jQuery );

Placeholder automático para vários campos usando jQuery

Para adicionar novos inputs, inclua no objeto _input_info o ID e o texto do placeholder

Exemplo funcional: http://codepen.io/anon/pen/DCnKI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment