小编17a*_*chi的帖子

带有粗体选项的可编辑 div

我想使用粗体斜体选项制作 contenteditable div,以使用相同的选项在 keyup 上的另一个 div 中显示内容。我设法显示文本,但不是选项。请帮忙

html:

<button onclick="document.execCommand('bold');">B</button>
<button onclick="document.execCommand('italic');">I</button>
<div id="textarea" contenteditable></div>
<div id="textarea-show"></div>
Run Code Online (Sandbox Code Playgroud)

查询:

$('#textarea').keyup(function() {
  $('#textarea-show').html($(this).text());
});
Run Code Online (Sandbox Code Playgroud)

css:

#textarea { background-color: #fff;
  border: 1px solid #ccc;
  color: #555;
  font-size: 14px;
  height: 34px;
  width: 450px;
}

  #textarea-show{font-size: 2rem;
  color:#666;
  height:50px;
  border: 1px solid #ccc;
  width: 450px;
}
Run Code Online (Sandbox Code Playgroud)

示例:https : //jsfiddle.net/gqmLtct7/1/

jquery bold contenteditable italic

8
推荐指数
1
解决办法
7642
查看次数

标签 统计

bold ×1

contenteditable ×1

italic ×1

jquery ×1