【发布时间】:2017-05-31 17:38:05
【问题描述】:
我有这个代码:
@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);
});
但这不起作用。第一个if 语句将被跳过,因为我只是想确保execCommand 正在工作。
它确实会打印出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 为 editor 的 div 传递给指令,以便它知道该特定按钮应该作用于什么。
【问题讨论】:
标签: angular typescript wysiwyg