Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Problem sa zamjenom

[es] :: Javascript i AJAX :: Problem sa zamjenom

[ Pregleda: 1467 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

Jezdimir Lončar
Aka Blazeme
PHP/jQuery Dev, BildStudio
Crna Gora / Pljevlja

Član broj: 74833
Poruke: 674
*.crnagora.net.

Jabber: jezdonet@gmail.com


+4 Profil

icon Problem sa zamjenom22.06.2007. u 08:52 - pre 205 meseci
Pozdrav!
Evo napravio sam neki edit-in-place, tj. preuzeo klasu za isti.
Posto radim sa BBCodeom, imao sam dosta problema.
Sad, ostao mi je jos jedan:
Kako da replaceujem [br] sa \n u textarea.
Kod izgleda ovako:
Code:

function edit(obj,reversed){
    Element.hide(obj);
    reversed = reversed.replace("[br]","\n");
    var textarea = '<div id="'+obj.id+'_editor"><textarea id="'+obj.id+'_edit" name="'+obj.id+'" rows="4" cols="60">'+trim(reversed)+'</textarea>';
    var button     = '<div style="align:center;"><input id="'+obj.id+'_save" type="button" value="Snimi promjene" /> <input id="'+obj.id+'_cancel" type="button" value="Otkazi" /></div></div>';
    
    new Insertion.After(obj, textarea+button);    
        
    Event.observe(obj.id+'_save', 'click', function(){saveChanges(obj)}, false);
    Event.observe(obj.id+'_cancel', 'click', function(){cleanUp(obj)}, false);
    
}

Medjutim, meni ono reversed = reversed.replace("[br]","\n"); nista ne uradi.
Evo primjera sta dobijem:
Code:

test
[b]Bold[/b][br][b]Bold2[/b][br][b]Bold3[/b]

Sta da radim?
Hvala,
Jezda.
// Edit:
// Ne bitno, sredio sam.

[Ovu poruku je menjao Neohacker dana 22.06.2007. u 13:56 GMT+1]
“I never think of the future - it comes soon enough.” - Albert Anštajn (Albert Einstein)
 
Odgovor na temu

dakipro
Dalibor Jovic
Web Developer
Bergen, Norway

Član broj: 31848
Poruke: 1792
82.208.211.*

Sajt: norway.dakipro.com


+190 Profil

icon Re: Problem sa zamjenom22.06.2007. u 15:42 - pre 205 meseci
Evo ti nesto sto ja koristim bas za edit-in-place
Code:

function getTextWithoutBROnly(el){
    return el.replace(/<br>/gi,'\n');
}
function getTextWithoutBR(el){
    return getTextWithoutBROnly(el.replace("/<br />/g",'\n'));
}

E sad, ne secam se zasto ide obe, valjda jedna zbog safari browsera na Mekintoshu a druga za ostale. Probaj pa vidi.
A mozes i da napises kako si sredio...
 
Odgovor na temu

[es] :: Javascript i AJAX :: Problem sa zamjenom

[ Pregleda: 1467 | Odgovora: 1 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.