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 hidden or 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 <[email protected]> | |
* @author Felipe Lavín <[email protected]> | |
*/ | |
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