简体   繁体   English

如何在文本区域添加更多文本

[英]How to add more text to textarea

I want to create console. 我要创建控制台。

I have textarea: 我有textarea:

<textarea style="width: 100%; height: 300px; resize: none;" id="console_output" readonly></textarea>

And using this code to insert more text: 并使用此代码插入更多文本:

else echo "<script>$('#console_output').append('Some text.\n');</script>";

But nothing happened, textarea is empty. 但是什么也没发生,textarea是空的。

Your code should work as you can check JsFiddle 您的代码应该可以正常工作,因为您可以检查JsFiddle

$('#console_output').append('Some text.\n');

Will not work if 如果不起作用

  1. you are not into your else statement 你不喜欢你的else陈述
  2. textarea is not there yet if dynamically created 如果动态创建,textarea尚不存在
  3. you have no jquery included 你没有包括jQuery

You can try with pure js: 您可以尝试使用纯js:

echo '<script>document.getElementById("console_output").value += "Some text.\n";</script>';

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

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