にフォーマットするためのexecCommandを使用して、私はこのコードを持っている:角度
@HostListener('document:click', ['$event'])
onClick(targetElement) {
console.log(targetElement);
var command = 'bold';
if (command == 'h1' || command == 'h2' || command == 'p') {
document.execCommand('formatBlock', false, command);
} else document.execCommand(targetElement.data('command'), false, null);
});
しかし、これは動作しませんが。 execCommand
が機能していることを確認したいので、最初のif
文はスキップされます。
console.log
を印刷してその機能に入ります。
変更されるHTML要素は次のとおりです。
<div id='editor' contenteditable>
<h1>A WYSIWYG Editor.</h1>
<p>Change this text, or format</p>
</div>
私は太字のために、選択したテキストを変更するにはどうすればよいですか? Typescriptでdocument.execCommandを使用するにはどうすればよいですか?
このセクションでは、document.execCommand(targetElement
というIDで、id:editor
のdivに渡すべきであると感じているので、その特定のボタンが何をするべきかを知っています。
ありがとうございます。これは私の出発点でした:https://codepen.io/Shokeen/pen/pgryyN –