Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Feb 2002
    Messaggi
    2

    funziona replace di java

    Premetto che di java capisco praticamente niente:
    Ho una textarea (si chiama titolo) dentro è contenuto del testo, devo fare in modo da aggiungere alla parte di testo selezionata dei tag html.
    Cosa sbaglio nel replace?

    grazie B.


    <script type="text/javascript">
    <!--
    function getgrasstitoloSel()
    {
    var tit='';
    tit=document.theform.titolo.value;

    var txt = '';
    var foundIn = '';
    if (window.getSelection)
    {
    txt = window.getSelection();
    foundIn = '';
    foundEnd = '
    ';

    }
    else if (document.getSelection)
    {
    txt = document.getSelection();
    foundIn = '';
    foundEnd = '
    ';
    }
    else if (document.selection)
    {
    txt = document.selection.createRange().text;
    foundIn = '';
    foundEnd = '
    ';

    }
    else return;
    t =foundIn + txt + foundEnd;
    t_re=new RegExp(t,"g");
    tit2= titolo.replace(txt, t_re);
    document.theform.titolo.value = tit2;
    }
    // -->
    </script>
    Bonnie

  2. #2
    Frontend samurai L'avatar di fcaldera
    Registrato dal
    Feb 2003
    Messaggi
    12,924
    a occhio vedo già che usi il replace in modo non corretto, ovvero passando come primo argomento una stringa mentre dovresti invece passare un'espressione regolare.
    Vuoi aiutare la riforestazione responsabile?

    Iscriviti a Ecologi e inizia a rimuovere la tua impronta ecologica (30 alberi extra usando il referral)

  3. #3
    Utente di HTML.it
    Registrato dal
    Feb 2002
    Messaggi
    2

    sempre replace di java...

    in effetti ho aggiunto ( ho ricopiato il codice di nuovo qui sotto....), ma il problema è che mi mette si i miei tag, ma aggiunge una barra prima e una dopo...
    verde /bianco / blu le barre non c'è modo di non farle venire?
    ripeto ignoto del tutto java...
    Barbara.




    <!--
    function getgrasstitoloSel()
    {
    var tit='';
    tit=document.theform.titolo.value;

    var txt = '';
    var foundIn = '';
    if (window.getSelection)
    {
    txt = window.getSelection();
    foundIn = '';
    foundEnd = '
    ';

    }
    else if (document.getSelection)
    {
    txt = document.getSelection();
    foundIn = '';
    foundEnd = '
    ';
    }
    else if (document.selection)
    {
    txt = document.selection.createRange().text;
    foundIn = '';
    foundEnd = '
    ';

    }
    else return;
    t =foundIn + txt + foundEnd;
    t_re=new RegExp(t);
    txt2=new RegExp(txt);
    tit2= tit.replace(txt2, t_re);
    document.theform.titolo.value = tit2;
    }
    // -->
    Bonnie

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.