繁体   English   中英

onchange和jQuery val()和text()的问题

[英]Problem with onchange and jQuery val() and text()

我有一个像这样的文本区域,现在我要在其中写入内容,我想在onc​​hange时将文本区域内容显示在我以前使用过的区域中

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


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

我认为一切都很好

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

但是当在其上使用荧光笔时,它不能那样工作

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

SyntaxHighlighter版本2.1.364(2009年10月15日)

你有没有尝试过,

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

那就是如果我们使用相同的highligher 如果有效,请尝试不要进行内联事件..;)欢呼...

而不是使用onchange =“”尝试使用

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

您可能还想尝试其他一些东西,例如.change()的.blur()instad。

也删除; 从你班上。 应显示为:

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

希望这有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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