Bonsoir,
J'essaie en vain ce test,
Ça ne marche pas.Code:
1
2 if ($(this).attr('value') == 'search...' || $(this).attr('value') == 'recherche...' ) $(this).attr('value', '');
Merci d'avance...
Version imprimable
Bonsoir,
J'essaie en vain ce test,
Ça ne marche pas.Code:
1
2 if ($(this).attr('value') == 'search...' || $(this).attr('value') == 'recherche...' ) $(this).attr('value', '');
Merci d'avance...
Est-ce que tu as une erreur ou est ce que ça renvoie juste false ?
Utilise "===" pour tes comparaisons autant que possible.
Que contient $(this).attr('value') quand tu fait un breakpoint sur la condition?
Et sinon, on pourrait voir à quoi correspond $(this) et le HTML associé ?Code:
1
2
3 if ($(this).val() == 'search...' || $(this).val() == 'recherche...' ) { $(this).val(''); }
seuleCode:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 <!-- HTML --> <li id="tool-search"> <form action="search.php" method="GET" id="recherche" class="formulaire_recherche"> <input type="text" id="search" name="search" value="{L_SEARCH}" class="span-4" /> <input type="submit" value="OK" class="fg-button ui-state-default ui-corner-all" /> </form> </li> //JS /* ---------------------- | SEARCH FOCUS IN/OUT ---------------------- */ var search = $('#tool-search input:first-child'); search.focus(function() { //if ($(this).attr('value') == 'search...') $(this).attr('value', ''); if ($(this).val() == 'search...' || $(this).val() == 'recherche...' ) { $(this).val(''); } try { origCol } catch(e) { origCol = $(this).css('color'); } $(this).css({color: '#333', fontWeight: 'normal'}); }); search.blur(function() { if ($(this).attr('value') == '') { $(this).attr('value', 'search...'); $(this).css({color: origCol, fontWeight: 'bold'}); } });
est détectée.Code:$(this).val() == 'search...'
Merci d'avance
Bonsoir
Exemple :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 var objSearch = $("#search"), tabValues = ["search...", "recherche...", ""], valeur; // avant jQuery 1.7 : bind au lieu de on objSearch.on("focusin", function(){ valeur = $(this).val(); if (valeur === tabValues[0] || valeur === tabValues[1]){ $(this).val(tabValues[2]); } }); objSearch.on("focusout", function() { valeur = $(this).val(); if (valeur === tabValues[2]){ $(this).val(tabValues[0]); } });