Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Formatowanie wpisywanego tekstu, jak zrobic button [B], [I]
senor_d
post
Post #1





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 17.02.2005
Skąd: skad

Ostrzeżenie: (0%)
-----


Nie moge rozwiazac problemu z funkcja w JS ktora po zaznaczeniu czesci tekstu w polu i nacisnieciu przycisku wykonywujacego funkcje obejmywalaby ten tekst w tagi np . Tak jak jest tutaj na tym forum w dodawaniu postow. Bardzo tego potrzebuje. Z gory dzieki
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
senor_d
post
Post #2





Grupa: Zarejestrowani
Postów: 26
Pomógł: 0
Dołączył: 17.02.2005
Skąd: skad

Ostrzeżenie: (0%)
-----


Działa i wygląda pieknie (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) . "SelectionStart", "SelectionEnd" - tego nie znalem. Teraz bedzie mozna to wykozystac i w innych przypadkach. Dzieki wielkie.

Upgrade'owalem troszeczke te funkcje.

Kod
function Bold() {

    var txtarea = document.getElementById("wpis");
    var selStart = txtarea.selectionStart;
    var selEnd = txtarea.selectionEnd;
    var length = ((txtarea.value).substring(selStart, selEnd)).length;
    var b = document.getElementById("b").value;

if (length >= 1) {

    document.getElementById("wpis").value = (txtarea.value).substring(0,selStart) + "[B]" +
    (txtarea.value).substring(selStart, selEnd) + "[/B]" + (txtarea.value).substring(selEnd,txtarea.value.length);

} else {

    if (b == "B") {

    document.getElementById("b").value = "B *";
    document.getElementById("wpis").value = (txtarea.value).substring(0,selStart) + "[B]" + (txtarea.value).substring(selEnd,txtarea.value.length);

    } else if (b == "B *") {

    document.getElementById("b").value = "B";
    document.getElementById("wpis").value = (txtarea.value).substring(0,selStart) + "[/B]" + (txtarea.value).substring(selEnd,txtarea.value.length);

    }

}

document.getElementById("wpis").focus();

}


  1. <input type="button" value="B" id="b" onClick="Bold()" onFocus="blur()">
  2. <textarea id="wpis"></textarea>

To dla takich jak ja zeby nie musieli juz szukac i pisac postow od niechcenia.

//edit
PILNE!! Czy ktos jest w stanie (ktos na pewno) dodac jeszcze w powyzszym skrypcie obsluge dla IE. Chodzi tu glownie o znajdowanie miejsca rozpoczecia i konca zaznaczenia. Problem jest tylko z IE. Probowalem TextRange() i createTextRange() ale za nic nie kumam jak znalezc ten poczatek i koniec (IMG:http://forum.php.pl/style_emoticons/default/sad.gif) POMOCY!!!

Ten post edytował senor_d 5.02.2006, 18:53:19
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 8.10.2025 - 13:53