Précédent   Forum des professionnels en informatique > Webmasters - Développement Web > JavaScript > Bibliothèques & Frameworks > jQuery
jQuery Forum d'entraide sur le framework jQuery. Avant de poster : Tutoriels jQuery, FAQ jQuery, Tous les tutoriels JavaScript, Toutes les FAQ JavaScript
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 30/09/2011, 19h08   #1
Membre éclairé
 
Homme Gérard Okono
Développeur Web
Inscription : juillet 2006
Messages : 711
Détails du profil
Informations personnelles :
Nom : Homme Gérard Okono
Localisation : Cameroun

Informations professionnelles :
Activité : Développeur Web
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : juillet 2006
Messages : 711
Points : 328
Points : 328
Par défaut Condition ne marche pas

Bonsoir,
J'essaie en vain ce test,
Code :
1
2
 
if ($(this).attr('value') == 'search...' || $(this).attr('value') == 'recherche...' ) $(this).attr('value', '');
Ça ne marche pas.

Merci d'avance...
okoweb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/09/2011, 19h22   #2
Invité de passage
 
Inscription : janvier 2009
Messages : 9
Détails du profil
Informations forums :
Inscription : janvier 2009
Messages : 9
Points : 3
Points : 3
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?
tominardi est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 30/09/2011, 19h31   #3
Responsable Développement Web

 
Avatar de Bovino
 
Homme Didier Mouronval
Développeur Web
Inscription : juin 2008
Messages : 13 807
Détails du profil
Informations personnelles :
Nom : Homme Didier Mouronval
Âge : 41
Localisation : France, Gironde (Aquitaine)

Informations professionnelles :
Activité : Développeur Web
Secteur : High Tech - Éditeur de logiciels

Informations forums :
Inscription : juin 2008
Messages : 13 807
Points : 35 789
Points : 35 789
Code :
1
2
3
if ($(this).val() == 'search...' || $(this).val() == 'recherche...' ) {
    $(this).val('');
}
Et sinon, on pourrait voir à quoi correspond $(this) et le HTML associé ?
__________________
Pas de question technique par MP !
Tout le monde peut participer à developpez.com, vous avez une idée, contactez-moi !
Vous possédez un blog et aimeriez diffuser vos billets sur le forum, contactez-moi !
Mes formations video2brain : La formation complète sur JavaScriptJavaScript et le DOM par la pratiquePHP 5 et MySQL : les fondamentaux
Mon livre sur jQuery
Bovino est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/10/2011, 08h37   #4
Membre éclairé
 
Homme Gérard Okono
Développeur Web
Inscription : juillet 2006
Messages : 711
Détails du profil
Informations personnelles :
Nom : Homme Gérard Okono
Localisation : Cameroun

Informations professionnelles :
Activité : Développeur Web
Secteur : Administration - Collectivité locale

Informations forums :
Inscription : juillet 2006
Messages : 711
Points : 328
Points : 328
Code :
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'});
	}
});
seule
Code :
$(this).val() == 'search...'
est détectée.
Merci d'avance
okoweb est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 01/10/2011, 21h10   #5
Rédacteur
 
Avatar de danielhagnoul
 
Homme Daniel Hagnoul
Étudiant perpétuel
Inscription : février 2009
Messages : 3 221
Détails du profil
Informations personnelles :
Nom : Homme Daniel Hagnoul
Âge : 61
Localisation : Belgique

Informations professionnelles :
Activité : Étudiant perpétuel
Secteur : Enseignement

Informations forums :
Inscription : février 2009
Messages : 3 221
Points : 6 767
Points : 6 767
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]);
	}
});
__________________

FAQ jQuery

Mon cahier d’exercices sur jQuery & Co

Si un message vous a aidé ou vous semble pertinent, votez pour lui !
danielhagnoul est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 03h46.


 
 
 
 
Partenaires

Hébergement Web