0
INDEX
Champs input
1 | < input type = "text" name = "login" value = 'Votre login' onFocus = "if (this.value=='Votre login') {this.value=''}" > |
Textareas
1 | < textarea name = "more" rows = "3" cols = "20" onFocus = "if (this.value=='Précisez') { this.value=''}" >Précisez</ textarea > |
Une variante en jQuery
1 2 3 4 5 6 7 8 9 | var el = $( 'input[type=text], textarea' ); el.focus( function (e) { if (e.target.value == e.target.defaultValue) e.target.value = '' ; }); el.blur( function (e) { if (e.target.value == '' ) e.target.value = e.target.defaultValue; }); |
La variante ultime en plugin jQuery
1 2 3 4 5 6 7 8 9 10 11 | $.fn.ToggleInputValue = function (){ return $( this ).each( function (){ var input = $( this ); var default_value = input.val(); input.focus( function () { if (input.val() == default_value) input.val( "" ); }).blur( function (){ if (input.val().length == 0) input.val(default_value); }); }); } |
DATE 20 Déc 2008