Visualizzazione dei risultati da 1 a 2 su 2
  1. #1

    Inserire testo in una textarea su testo selezionato

    Salve,

    Sto usando questo Javascript
    codice:
    function addtag(tag) {
            var obj=document.Form1.text;
            if (document.all) {
                    obj.focus();
                      var sel=document.selection;
                      var rng=sel.createRange();
                      rng.colapse;
                      rng.text=tag;
            } else if(obj.selectionEnd){
                    var lng=obj.textLength;
                    var from=obj.selectionStart;
                    var to=obj.selectionEnd;
                    obj.value=obj.value.substring(0,from)+tag+obj.value.substring(to,lng)
            } else obj.value+=tag;
            obj.focus();
            }
    Che ho trovato sul forum, mi ritengo abbastanza soddisfatto di come funziona, ma vorrei provare a fare qualcosa di più complicato...o perlomeno, mi affido a voi visto che come JS sto abbastanza a 0
    Vorrei fare uno script che se non c'è nulla selezionato esegua la funzione che c'è in questo post, altrimenti se c'è del testo selezionato, inserisce qualcosa tra la parte selezionata, ad esempio, se non ho nulla selezionato, scrive solo [b], mentre invece se ho del testo selezionato scrive Testo, dove Testo è il testo che ho selezionato.

    è possibile, o chiedo troppo?
    The gate to tomorrow is not the light of heaven but the darkness in the depth of the earth

  2. #2
    up
    The gate to tomorrow is not the light of heaven but the darkness in the depth of the earth

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 © 2024 vBulletin Solutions, Inc. All rights reserved.