Partage
  • Partager sur Facebook
  • Partager sur Twitter

Aide avec condition javascript

Sujet résolu
    26 octobre 2008 à 21:14:29

    Salut !

    Après plusieurs tentatives, j'abandonne...et je demande votre aide ! :D
    J'ai téléchargé un script sur Internet qui modifie chacun de mes liens <a>
    Je voudrais le modifier pour qu'il modifie seulement les <a> qui ont id="title"
    Comment est-ce que je peux faire ce genre de code en javascript o_O :


    If(le 'id' de cet élément là = "title")
    {
    this code;
    }

    Merci !
    • Partager sur Facebook
    • Partager sur Twitter
      26 octobre 2008 à 22:14:09

      Hello elite_thut,

      Envoie le script en question qu'on puisse le modifier, sinon c'est exactement ça ;)
      if (node.id == 'title') {}
      

      :magicien:
      • Partager sur Facebook
      • Partager sur Twitter
        27 octobre 2008 à 0:35:40

        Et bien, il est un peu trop gros pour que puisse toute vous l'envoyer...

        Voici la section que je veux modifier avec en rouge ce que j'ai rajouté...mais ça ne fonctionne toujours pas.

        tipShow : function() {
                                var scrX = Number(this.xCord);
                                var scrY = Number(this.yCord);
                                var tp = parseInt(scrY+15);
                                var lt = parseInt(scrX+10);
                                var anch = this.checkNode();
                                var addy = '';
                                var access = '';
                                if ( anch.nodeName.toLowerCase() == 'a' ) {
                                        addy = (anch.href.length > 25 ? anch.href.toString().substring(0,25)+"..." : anch.href);
                                        var access = ( anch.accessKey ? ' <span>['+anch.accessKey+']</span> ' : '' );
                                } else {
                                        addy = anch.firstChild.nodeValue;
                                }
                                this.tip.innerHTML = "<p>"+anch.getAttribute('tip')+"</p>";
                                if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(this.tip.offsetWidth+lt) ) {
                                        this.tip.style.left = parseInt(lt-(this.tip.offsetWidth+10))+'px';
                                } else {
                                        this.tip.style.left = lt+'px';
                                }
                                if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(this.tip.offsetHeight+tp) ) {
                                        this.tip.style.top = parseInt(tp-(this.tip.offsetHeight+10))+'px';
                                } else {
                                        this.tip.style.top = tp+'px';
                                }
                              <couleur nom="rouge">  if (node.id=='title'){
                                this.tip.style.visibility = 'visible';
                                }
                                else{
                                this.tip.style.visibility = 'invisible';
                                }</couleur>
                                this.tip.style.opacity = '.1';
                                this.tipFade(10);
                        }
        • Partager sur Facebook
        • Partager sur Twitter
          27 octobre 2008 à 1:44:10

          Remplaces node par this.tip et ça ira tout seul ;)

          Ah, et invisible n'existe pas, c'est hidden :magicien:
          • Partager sur Facebook
          • Partager sur Twitter
            27 octobre 2008 à 4:05:30

            tipShow : function() {
                                    var scrX = Number(this.xCord);
                                    var scrY = Number(this.yCord);
                                    var tp = parseInt(scrY+15);
                                    var lt = parseInt(scrX+10);
                                    var anch = this.checkNode();
                                    var addy = '';
                                    var access = '';
                                    if ( anch.nodeName.toLowerCase() == 'a' ) {
                                            addy = (anch.href.length > 25 ? anch.href.toString().substring(0,25)+"..." : anch.href);
                                            var access = ( anch.accessKey ? ' <span>['+anch.accessKey+']</span> ' : '' );
                                    } else {
                                            addy = anch.firstChild.nodeValue;
                                    }
                                    this.tip.innerHTML = "<p>"+anch.getAttribute('tip')+"</p>";
                                    if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(this.tip.offsetWidth+lt) ) {
                                            this.tip.style.left = parseInt(lt-(this.tip.offsetWidth+10))+'px';
                                    } else {
                                            this.tip.style.left = lt+'px';
                                    }
                                    if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(this.tip.offsetHeight+tp) ) {
                                            this.tip.style.top = parseInt(tp-(this.tip.offsetHeight+10))+'px';
                                    } else {
                                            this.tip.style.top = tp+'px';
                                    }
                                    if (this.tip.id=='title'){
                                    this.tip.style.visibility = 'visible';
                                    }
                                    else{
                                    this.tip.style.visibility = 'hidden';
                                    }
                                    this.tip.style.opacity = '.1';
                                    this.tipFade(10);
                    }


            Avec ce code, j'ai fait quelques tests...et c'est le "else" qui est exécuté...donc, ça ne fonctionne pas. :euh:
            • Partager sur Facebook
            • Partager sur Twitter
              27 octobre 2008 à 4:44:02

              Correction : Remplaces this.tip par anch et ça ira tout seul, puisque c'est ainsi qu'est nommé le lien ;)
              • Partager sur Facebook
              • Partager sur Twitter
                27 octobre 2008 à 4:59:33

                WOW !!! Ça fonctionne !!! Je n'y croyais plus :p


                Merci beaucoup !
                • Partager sur Facebook
                • Partager sur Twitter

                Aide avec condition javascript

                × 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