Skip to content

Instantly share code, notes, and snippets.

@phenix-factory
Last active December 16, 2015 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phenix-factory/5371089 to your computer and use it in GitHub Desktop.
Save phenix-factory/5371089 to your computer and use it in GitHub Desktop.
jQuery: Simuler un PlaceHolder avec du javascript.
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