Last active
December 16, 2015 03:39
-
-
Save phenix-factory/5371089 to your computer and use it in GitHub Desktop.
jQuery: Simuler un PlaceHolder avec du javascript.
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
jQuery(document).ready(function($) { | |
// Le sélécteur de champ. | |
var typeInput = $("input[type=text], input[type=password], input[type=search], input[type=email]"); | |
// Quand on un champ de formulaire prend le focus | |
typeInput.on("focusin", function () { | |
// On récupère ça valeur | |
value = $(this).val(); | |
// Si c'est la valeur par défaut, on vide le champs. | |
if (value == this.defaultValue) $(this).val(""); | |
}); | |
// Quand le champs perd le focus | |
typeInput.on("focusout",function () { | |
// Si le champs est vide on remet la valeur par defaut. | |
if ($(this).val() == "") $(this).val(this.defaultValue); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment