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 :

Changer texte dans colonne table


Sujet :

jQuery

  1. #1
    Membre du Club
    Inscrit en
    Juillet 2009
    Messages
    201
    Détails du profil
    Informations forums :
    Inscription : Juillet 2009
    Messages : 201
    Points : 48
    Points
    48
    Par défaut Changer texte dans colonne table
    Bonjour,

    Dans ma table suivante lorsque je clique sur le DIV situé dans la colonne N°4 je voudrais modifier le texte de la colonne N°3 :

    Si texte = on alors texte = off
    Si texte = off alors texte = on

    Mais je n'arrive pas à le faire... J'essaye de récupérer l'ID du TD, mais je n'y parviens pas.

    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
    <table class="Tab">
    <tr><th>COL1</th><th>COL2</th><th>COL3</th><th>COL4</th></tr>
    <tr>
            <td>Ligne 1</td>
            <td id="11">11</td>
            <td>off</td>
            <td class="edit"><div onclick="change(11,this)"></div></td></tr>
    <tr>
            <td>Ligne 2</td>
            <td id="12">12</td>
            <td>off</td>
            <td class="edit"><div onclick="change(12,this)"></div></td></tr>
    <tr>
            <td>Ligne 3</td>
            <td id="3">3</td>
            <td>off</td>
            <td class="edit"><div onclick="change(3,this)"></div></td></tr>
    </tr>
    </table>

    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    <div onclick="change(3,this)">
    Je change juste l'image sur le onclick...


  2. #2
    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 : 74
    Localisation : Belgique

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

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

    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
    <table class="Tab">
    	<thead>
    		<tr>
    			<th>COL1</th>
    			<th>COL2</th>
    			<th>COL3</th>
    			<th>COL4</th>
    		</tr>
    	</thead>
    	<tbody>
    		<tr>
    	        <td>Ligne 1</td>
    	        <td id="td11">11</td>
    	        <td>off</td>
    	        <td class="edit">
    	        	<div>Cliquez-moi !</div>
    	        </td>
    	    </tr>
    		<tr>
    	        <td>Ligne 2</td>
    	        <td id="td12">12</td>
    	        <td>off</td>
    	        <td class="edit">
    	        	<div>Cliquez-moi !</div>
    	        </td>
    	    </tr>
    		<tr>
    	        <td>Ligne 3</td>
    	        <td id="td3">3</td>
    	        <td>off</td>
    	        <td class="edit">
    	        	<div>Cliquez-moi !</div>
    	        </td>
    		</tr>
    	</tbody>
    </table>

    Code JavaScript : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    /*
     * Si texte = on alors texte = off
     * Si texte = off alors texte = on
     */
    $( "td.edit" ).on( "click", function(){
    	var jObj = $( this ).prev(),
    	    str = ( jObj.text() == "off" ) ? ( "on" ) : ( "off" );
     
    	// debug
    	// console.log( jObj, str );
     
    	jObj.text( str );
    });

Discussions similaires

  1. [VB6]Importer un fichier texte dans une table ACCESS
    Par jean-pierre96 dans le forum VB 6 et antérieur
    Réponses: 6
    Dernier message: 26/02/2013, 15h55
  2. Recherche plein texte dans plusieurs tables
    Par GCAccess dans le forum Access
    Réponses: 1
    Dernier message: 08/02/2007, 18h29
  3. Réponses: 5
    Dernier message: 23/08/2006, 19h42
  4. Réponses: 7
    Dernier message: 23/06/2006, 14h52
  5. [MySQL] Inscription d'un texte dans la table
    Par glloq8 dans le forum PHP & Base de données
    Réponses: 4
    Dernier message: 23/09/2005, 16h44

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