Last active
May 3, 2018 22:49
-
-
Save lucasmezencio/3931326 to your computer and use it in GitHub Desktop.
jQuery 'plugin' dor defaultvalue of an input
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
;(function($) { | |
$.fn.defaultValue = function() { | |
$(this).each(function(i, el) { | |
var actualValue, | |
$el = $(this), | |
defaultValue = el.value; | |
$el.on('focus', function() { | |
actualValue = $el.val(); | |
if (actualValue == defaultValue) { | |
$el.val(''); | |
} | |
}); | |
$el.on('blur', function() { | |
actualValue = $el.val(); | |
if (!actualValue) { | |
$el.val(defaultValue); | |
} | |
}); | |
}); | |
} | |
})(jQuery); |
Opa, só vi seu comentário agora.
Sim, tô ligado, mas ele não funciona em todos os browsers (infelizmente).
=]
thnx
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Vc tá ligado que existe o atributo placeholder que faz exatamente isso né?