使所选文字变为粗体:
document.execCommand('bold', null, null);
当用户再次选择该段文本(或其中的一部分)时,您怎么知道它已变为粗体?
Bold就是一个例子。 commandName
可以是underline
,heading
,createLink
,...
答案 0 :(得分:12)
document.queryCommandState
确定是否已对当前执行给定命令 选择。
来源:http://blog.whatwg.org/the-road-to-html-5-contenteditable#how
显然我搜索得不够好。
答案 1 :(得分:0)
你会知道它是大胆的,因为它被<b></b>
标签包裹着。 (或用户代理用于粗体文本的任何内容)