【问题标题】:select a text from textarea and press the button to make them bold [duplicate]从 textarea 中选择一个文本并按下按钮使它们变为粗体 [重复]
【发布时间】:2022-01-24 05:03:23
【问题描述】:

当有人选择文本并按下粗体按钮时,所选文本将变为粗体,而不是所有 textarea 字符。

document.getElementById("bold").onclick = function() {
  document.getElementById("textarea").style.fontWeight = "800";
}
<textarea id="textarea"></textarea>
<button id="bold">Make bold</button>

【问题讨论】:

    标签: javascript html css


    【解决方案1】:

    您不能在文本区域内设置比您的示例更多的文本样式。

    但您可以尝试使用可编辑 div 进行此尝试:https://stackoverflow.com/a/50287002/4230037

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-12
      • 1970-01-01
      • 1970-01-01
      • 2021-02-03
      • 1970-01-01
      • 1970-01-01
      • 2023-03-28
      • 1970-01-01
      相关资源
      最近更新 更多