LoginSignup
0

More than 5 years have passed since last update.

外部プラグインなしで簡単にリッチテキストエディタを実装

Last updated at Posted at 2015-09-26

いわゆるwysiywgですね。
html5のcontentEditableというものを使うと簡単にできます。
こんな感じです。

<button type='button' onclick='return bold()'>太字</button>
<button type='button' onclick='return underline()'>下線</button>

<div contentEditable='true' style='width:200px; height:100px; border:solid 1px #ddd'></div>

<script>
  function bold() {
    document.execCommand('bold', false);
  }
  function underline() {
    document.execCommand('underline', false);
  }
</script>

そのほかにも色をつける、リンクを作成、画像挿入などもでき、一般的なリッチテキストエディタの機能は実装可能です。

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0