IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

jQuery Discussion :

fonction colorer table html


Sujet :

jQuery

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Candidat au Club
    Inscrit en
    Octobre 2012
    Messages
    2
    Détails du profil
    Informations forums :
    Inscription : Octobre 2012
    Messages : 2
    Par défaut fonction colorer table html
    Bonjour tout le monde
    j'ai crée une fonction qui permet de colorer les lignes d'un tableau html en utilisaant even et odd la fonction est la suivante :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    function colorer(tb)
    {
    $(tb).children("tbody tr:odd").addClass("couleur1");//définie dans le style
    $(tb).children("tbody tr:even").addClass("couleur2"); //définie dans le style
    }
    mais le problème est si j'applique cette fonction sur deux tables la 1ère donne le résultat souhaité le 2ème prend la couleur de odd toute entière
    aidez-moi svp

  2. #2
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 659
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 75
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 659
    Billets dans le blog
    1
    Par défaut
    a mon avis ou souci de balises html mal balancées ...

    encore faudrait il pouvoir en juger à la vue de ton code html
    Ma page Developpez - Mon Blog Developpez
    Président du CCMPTP (Comité Contre le Mot "Problème" dans les Titres de Posts)
    Deux règles du succès: 1) Ne communiquez jamais à quelqu'un tout votre savoir...
    Votre post est résolu ? Alors n'oubliez pas le Tag

    Venez sur le Chat de Développez !

  3. #3
    Rédacteur

    Avatar de danielhagnoul
    Homme Profil pro
    Étudiant perpétuel
    Inscrit en
    Février 2009
    Messages
    6 389
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 75
    Localisation : Belgique

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

    Informations forums :
    Inscription : Février 2009
    Messages : 6 389
    Billets dans le blog
    125
    Par défaut
    Bonsoir

    Exemple :
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    <!DOCTYPE html>
    <html lang="fr" dir="ltr">
    <head>
    	<meta charset="utf-8">
    	<meta name="viewport" content="initial-scale=1.0">
    	<meta name="author" content="Daniel Hagnoul">
    	<title>Forum jQuery</title>
    	<script src="http://cdnjs.cloudflare.com/ajax/libs/headjs/0.99/head.min.js"></script>
    	<script>
                    "use strict";
                                                    
                    head.js( 
                            "http://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.0/raphael-min.js", 
                            //"http://code.jquery.com/jquery-1.10.1.min.js",
                            "http://code.jquery.com/jquery-2.0.2.min.js",
                            "http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/i18n/jquery-ui-i18n.min.js",
                            "http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js",
                            "http://danielhagnoul.developpez.com/lib/dvjh/base.js",
                            "http://cdnjs.cloudflare.com/ajax/libs/jquery-url-parser/2.2.1/purl.min.js",
                            function(){
     
                                    $( function(){
                                            
                                            $( "tbody > tr:odd", "table" ).css( "background-color", "yellow" );
                                            
                                            $( "tbody > tr:even", "table" ).addClass( "couleurEven" );
                                            
                                    });
                                    
                                    $( window ).load( function(){
                                            
                                    });
                            }
                    );
            </script>
    	<link href='http://fonts.googleapis.com/css?family=Sofia|Ubuntu:400|Kreon'>
    	<link rel="stylesheet" href="http://danielhagnoul.developpez.com/styles/dvjhRemBase.css">
    	<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/sunny/jquery-ui.min.css">
    	<style>
                    /* TEST -- Nota bene : ici 1 rem est égal à 1 px, voir dvjhRemBase.css */
                    .couleurEven { background-color: lightgreen; }
            </style>
    </head>
    <body>
    	<header>
    		<hgroup>
    			<h1>Forum jQuery</h1>
    			<h2>
    				<a href="">Lien</a>
    			</h2>
    		</hgroup>
    	</header>
    	<section class="conteneur">
     
    <table>
    	<thead>
    		<tr>
    		     <th>Lun</th>
    		     <th>Mar</th>
    		     <th>Mer</th>
    		     <th>Jeu</th>
    		     <th>Ven</th>
    		     <th>Sam</th>
    		     <th>Dim</th>		     
    		 </tr>
    	</thead>
    	<tbody>
    		<tr>
    			<td>0</td>
    			<td>1</td>
    			<td>2</td>
    			<td>3</td>
    			<td>4</td>
    			<td>5</td>
    			<td>6</td>
    		</tr>
    		<tr>
    			<td>1</td>
    			<td>2</td>
    			<td>3</td>
    			<td>4</td>
    			<td>5</td>
    			<td>6</td>
    			<td>7</td>
    		</tr>
    		<tr>
    			<td>2</td>
    			<td>3</td>
    			<td>4</td>
    			<td>5</td>
    			<td>6</td>
    			<td>7</td>
    			<td>8</td>
    		</tr>
    		<tr>
    			<td>0</td>
    			<td>1</td>
    			<td>2</td>
    			<td>3</td>
    			<td>4</td>
    			<td>5</td>
    			<td>6</td>
    		</tr>
    		<tr>
    			<td>1</td>
    			<td>2</td>
    			<td>3</td>
    			<td>4</td>
    			<td>5</td>
    			<td>6</td>
    			<td>7</td>
    		</tr>
    		<tr>
    			<td>2</td>
    			<td>3</td>
    			<td>4</td>
    			<td>5</td>
    			<td>6</td>
    			<td>7</td>
    			<td>8</td>
    		</tr>
    		<tr>
    			<td>0</td>
    			<td>1</td>
    			<td>2</td>
    			<td>3</td>
    			<td>4</td>
    			<td>5</td>
    			<td>6</td>
    		</tr>
    		<tr>
    			<td>1</td>
    			<td>2</td>
    			<td>3</td>
    			<td>4</td>
    			<td>5</td>
    			<td>6</td>
    			<td>7</td>
    		</tr>
    		<tr>
    			<td>2</td>
    			<td>3</td>
    			<td>4</td>
    			<td>5</td>
    			<td>6</td>
    			<td>7</td>
    			<td>8</td>
    		</tr>
    		<tr>
    			<td>0</td>
    			<td>1</td>
    			<td>2</td>
    			<td>3</td>
    			<td>4</td>
    			<td>5</td>
    			<td>6</td>
    		</tr>
    		<tr>
    			<td>1</td>
    			<td>2</td>
    			<td>3</td>
    			<td>4</td>
    			<td>5</td>
    			<td>6</td>
    			<td>7</td>
    		</tr>
    		<tr>
    			<td>2</td>
    			<td>3</td>
    			<td>4</td>
    			<td>5</td>
    			<td>6</td>
    			<td>7</td>
    			<td>8</td>
    		</tr>
    	</tbody>
    </table>
     
    <table>
    	<thead>
    		<tr>
    		     <th>Prix en €/T</th>
    		     <th>01/01</th>
    		     <th>01/02</th>
    		     <th>01/03</th>
    		 </tr>
    	</thead>
    	<tbody>
    		<tr>
    			<th>Pommes</th>
    			<td>50</td>
    			<td>40</td>
    			<td>90</td>
    		</tr>
    		<tr>
    			<th>Poires</th>
    			<td>15</td>
    			<td>30</td>
    			<td>25</td>
    		</tr>
    		<tr>
    			<th>Pommes</th>
    			<td>50</td>
    			<td>40</td>
    			<td>90</td>
    		</tr>
    		<tr>
    			<th>Poires</th>
    			<td>15</td>
    			<td>30</td>
    			<td>25</td>
    		</tr>
    		<tr>
    			<th>Pommes</th>
    			<td>50</td>
    			<td>40</td>
    			<td>90</td>
    		</tr>
    		<tr>
    			<th>Poires</th>
    			<td>15</td>
    			<td>30</td>
    			<td>25</td>
    		</tr>
    		<tr>
    			<th>Pommes</th>
    			<td>50</td>
    			<td>40</td>
    			<td>90</td>
    		</tr>
    		<tr>
    			<th>Poires</th>
    			<td>15</td>
    			<td>30</td>
    			<td>25</td>
    		</tr>
    		<tr>
    			<th>Pommes</th>
    			<td>50</td>
    			<td>40</td>
    			<td>90</td>
    		</tr>
    		<tr>
    			<th>Poires</th>
    			<td>15</td>
    			<td>30</td>
    			<td>25</td>
    		</tr>
    	</tbody>
    </table>
     
     
    	</section>
    	<footer itemscope itemtype="http://danielhagnoul.developpez.com/">
    		<time datetime="2013-06-26T23:03:08.634+02:00" pubdate>2013-06-26T23:03:08.634+02:00</time>
    		<span itemprop="name">Daniel Hagnoul</span>
    		<a href="http://www.developpez.net/forums/u285162/danielhagnoul/" itemprop="url">@danielhagnoul</a>
    		<a href="http://danielhagnoul.developpez.com/" itemprop="url">Mon cahier d’exercices</a>
    		<a href="http://javascript.developpez.com/faq/jquery/" itemprop="url">FAQ</a>
    		<a href="http://javascript.developpez.com/cours/?page=frameworks#jquery" itemprop="url">Tutoriels</a>
    	</footer>
    </body>
    </html>

    Blog

    Sans l'analyse et la conception, la programmation est l'art d'ajouter des bogues à un fichier texte vide.
    (Louis Srygley : Without requirements or design, programming is the art of adding bugs to an empty text file.)

Discussions similaires

  1. Afficher du XML dans une table HTML avec fonction récursive (ou pas)
    Par iviewclear dans le forum Général JavaScript
    Réponses: 14
    Dernier message: 19/04/2010, 17h04
  2. Fonction mail avec HTML et images
    Par nico33307 dans le forum Modules
    Réponses: 1
    Dernier message: 05/07/2005, 23h25
  3. [SQL-Interbase] Fonction SHOW TABLES
    Par polocfa41 dans le forum InterBase
    Réponses: 4
    Dernier message: 26/04/2005, 11h33
  4. Fonctions et tables temporaires ?!
    Par devdev dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 16/12/2004, 11h46
  5. Réponses: 8
    Dernier message: 13/08/2004, 12h32

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo