简体   繁体   English

将 textarea 中的特定文本设为粗体

[英]Making specific text in textarea bold

I am making an chatbox in which for displaying chat history I used textarea which is readonly.... what I want is to make the starting text "Me: " Bold我正在制作一个聊天框,在其中显示聊天记录我使用了只读的 textarea....我想要的是使起始文本“我:”加粗

document.getElementById(messagearea).value = 
document.getElementById(messagearea).value + "\n <b>Me:</b>" + message1;

Any help?有什么帮助吗?

It's not possible to format part of the text in a textarea.无法在 textarea 中格式化部分文本。 Instead place the text in a <div> .而是将文本放在<div>

<div id="messages" style="white-space: pre-wrap"></div>

With jQuery:使用 jQuery:

$('#messages').append("<div><b>Me:</b>" + message1 + "</div>")

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

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