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 pr开发者_如何学Pythone 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.
精彩评论