Created
April 12, 2010 04:23
-
-
Save felipelavinz/363269 to your computer and use it in GitHub Desktop.
Simple jQuery plugin to set sample content on text inputs and automatically clean it on focus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A simple jQuery plugin to set sample content on text inputs | |
* and automatically clean it on focus | |
* @author Basilio Cáceres <bcaceres@ayerviernes.com> | |
* @author Felipe Lavín <flavin@ayerviernes.com> | |
*/ | |
jQuery.fn.buscDef = function() { | |
var orVal = jQuery(this).val(); | |
if ( jQuery.trim(orVal) != '' ) { | |
jQuery(this).data( 'defVal', orVal ) | |
} else { | |
jQuery(this).data( 'defVal', 'Buscar' ) | |
} | |
jQuery(this).blur(function() { | |
if ( jQuery(this).val() == '' ) { | |
jQuery(this).val( jQuery(this).data('defVal') ) | |
} | |
}).focus(function() { | |
jQuery(this).select(); | |
if ( jQuery(this).val() == jQuery(this).data('defVal') ) { | |
jQuery(this).val(''); | |
} | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment