Partage
  • Partager sur Facebook
  • Partager sur Twitter

Jquery : Fonction s'exécutant à l'affichage

Sujet résolu
Anonyme
    11 août 2010 à 16:31:00

    Bonjour,
    J'ai un problème avec Jquery, effectivement, j'ai une fonction qui s'exécute au clic sur un bloc. Malheureusement, je voudrais que la fonction s'exécute à l'affichage de la page, mon code :

    $('.conteneur1').load(function(){
            $.gritter.add({
    			// (string | mandatory) the heading of the notification
    			title: 'Connexion',
    			// (string | mandatory) the text inside the notification
    			text: 'Le pseudo <?php echo htmlspecialchars($_POST['pseudo'], ENT_QUOTES); ?> n\'existe pas. Vous avez probablement fait une erreur.',
    			// (string | optional) the image to display on the left
    			image: 'images/error.png',
    			// (bool | optional) if you want it to fade out on its own or just sit there
    			sticky: true,
    			// (int | optional) the time you want it to be alive for before fading out (milliseconds)
    			time: 8000
    		}); 
            return flase;
       	});
    


    Code de base :

    $('.conteneur1').click(function(){
            $.gritter.add({
    			// (string | mandatory) the heading of the notification
    			title: 'Connexion',
    			// (string | mandatory) the text inside the notification
    			text: 'Le pseudo <?php echo htmlspecialchars($_POST['pseudo'], ENT_QUOTES); ?> n\'existe pas. Vous avez probablement fait une erreur.',
    			// (string | optional) the image to display on the left
    			image: 'images/error.png',
    			// (bool | optional) if you want it to fade out on its own or just sit there
    			sticky: true,
    			// (int | optional) the time you want it to be alive for before fading out (milliseconds)
    			time: 8000
    		}); 
            return flase;
       	});
    

    C'est au début du code qu'il faut regarder, moi j'ai remplacé le click par load :)
    Mais ça ne marche pas :(
    Merci
    • Partager sur Facebook
    • Partager sur Twitter
      11 août 2010 à 16:32:36

      Hmmm j'ai lu un truc la dessus... Le problème viens du DOM.

      Tu test avec quel navigateur là?
      • Partager sur Facebook
      • Partager sur Twitter
        11 août 2010 à 16:44:16

        Salut,

        Avec JQuery, si tu veux exécuter du code au chargement de la page, tu dois faire comme ceci :

        $().ready(function(){
           // ton code à exécuter ici
        });
        
        • Partager sur Facebook
        • Partager sur Twitter
        Directeur technique, créateur de jeux HTML5 et fan de JavaScript | La suite de OnHack est sur les rails !
        Anonyme
          11 août 2010 à 16:49:42

          Citation : Shivaan

          Salut,

          Avec JQuery, si tu veux exécuter du code au chargement de la page, tu dois faire comme ceci :

          $().ready(function(){
             // ton code à exécuter ici
          });
          


          Oui c'est bien quelque chose comme ça que j'ai lu ^^, merci, j'avais un peu la flemme de rechercher a nouveau :p
          • Partager sur Facebook
          • Partager sur Twitter
          Anonyme
            11 août 2010 à 16:52:50

            Donc j'enlèves le $('.conteneur1').load(function(){ ?
            • Partager sur Facebook
            • Partager sur Twitter
              11 août 2010 à 16:53:51

              Oui
              • Partager sur Facebook
              • Partager sur Twitter
              Directeur technique, créateur de jeux HTML5 et fan de JavaScript | La suite de OnHack est sur les rails !
              Anonyme
                11 août 2010 à 16:54:14

                Ca ne marche pas :(

                Mon nouveau code :
                $().ready(function(){
                		$.gritter.add({
                			// (string | mandatory) the heading of the notification
                			title: 'Connexion',
                			// (string | mandatory) the text inside the notification
                			text: 'Vous &ecirc;tes d&eacute;sormais connect&eacute;.',
                			// (string | optional) the image to display on the left
                			image: 'images/info.png',
                			// (bool | optional) if you want it to fade out on its own or just sit there
                			sticky: true,
                			// (int | optional) the time you want it to be alive for before fading out (milliseconds)
                			time: 8000
                		});  
                        return flase;
                   	});
                


                J'utilise jGritter
                http://boedesign.com/demos/gritter/
                • Partager sur Facebook
                • Partager sur Twitter
                  11 août 2010 à 16:56:32

                  Je pense qu'il faut également remplacer
                  $.gritter.add
                  

                  par
                  $('.conteneur1').gritter.add
                  
                  • Partager sur Facebook
                  • Partager sur Twitter
                  Directeur technique, créateur de jeux HTML5 et fan de JavaScript | La suite de OnHack est sur les rails !
                  Anonyme
                    11 août 2010 à 17:02:55

                    Ok, je ne connaissais pas ce plugin. le code suivant devrait marcher alors

                    $().ready(function(){
                       $('.conteneur1').click(function(){
                          $.gritter.add({
                             // (string | mandatory) the heading of the notification
                             title: 'Connexion',
                             // (string | mandatory) the text inside the notification
                             text: 'Vous &ecirc;tes d&eacute;sormais connect&eacute;.',
                             // (string | optional) the image to display on the left
                             image: 'images/info.png',
                             // (bool | optional) if you want it to fade out on its own or just sit there
                             sticky: true,
                             // (int | optional) the time you want it to be alive for before fading out (milliseconds)
                             time: 8000
                          });  
                          return false;
                       });
                    });
                    
                    • Partager sur Facebook
                    • Partager sur Twitter
                    Directeur technique, créateur de jeux HTML5 et fan de JavaScript | La suite de OnHack est sur les rails !
                    Anonyme
                      11 août 2010 à 17:04:52

                      Ca ne marche pas :(
                      En même temps tu as laissé le click alors...
                      • Partager sur Facebook
                      • Partager sur Twitter
                        11 août 2010 à 17:09:49

                        Oui, je fais mon noob sur le coup. Je suis tellement absorbé par la modération que je ne prends pas le temps de réfléchir correctement à ton problème.

                        Bon, mon code final devrait être le suivant. Si ça ne marche pas, il faudra que d'autres viennent à ton aide ^^

                        $().ready(function(){
                           $('.conteneur1').gritter.add({
                                 // (string | mandatory) the heading of the notification
                                 title: 'Connexion',
                                 // (string | mandatory) the text inside the notification
                                 text: 'Vous &ecirc;tes d&eacute;sormais connect&eacute;.',
                                 // (string | optional) the image to display on the left
                                 image: 'images/info.png',
                                 // (bool | optional) if you want it to fade out on its own or just sit there
                                 sticky: true,
                                 // (int | optional) the time you want it to be alive for before fading out (milliseconds)
                                 time: 8000
                              });  
                              return false;
                        });
                        
                        • Partager sur Facebook
                        • Partager sur Twitter
                        Directeur technique, créateur de jeux HTML5 et fan de JavaScript | La suite de OnHack est sur les rails !
                        Anonyme
                          11 août 2010 à 17:11:21

                          Ben je vais devoir demander à d'autres XD
                          Ne marche pas :(
                          • Partager sur Facebook
                          • Partager sur Twitter

                          Jquery : Fonction s'exécutant à l'affichage

                          × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
                          × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
                          • Editeur
                          • Markdown