简体   繁体   中英

Problem with onchange and jQuery val() and text()

i have an text area like this one which i write in it now now i want when onchange the textarea content appear in a pre i used

<textarea id="content" onchange="perview();"></textarea>


function perview() {
var code = $("textarea#content").val();
$('#code-preview').html(code);
}   

i think every thing is ok

<pre id="code-preview"></pre> 

but when using highlighter on the pre its not working like that

<pre id="code-preview" class="brush: php;"></pre>

the SyntaxHighlighter version 2.1.364 (October 15 2009)

have you tried,

function perview() {
   var code = $("textarea#content").val();
    $('#code-preview').html(code);
    SyntaxHighlighter.all() // <--- calling this again...
} 

that is if we are using same highligher . if that works, please try not inline events.. ;) cheers...

instead of using onchange="" try using

$(document).ready(function(){
     $('textarea#content').change(function(){
          var code = $(this).val();
          $('#code-preview').html(code);
     });
});

you may also want to try a few other things such as .blur() instad of .change().

also remove the ; from your class. that should read:

<pre id="code-preview" class="brush:php"></pre>

I hope this has been helpful.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM