HTML5 contentEditable检查是否使用execCommand应用了格式?

时间:2011-07-16 23:03:49

标签: javascript html5 contenteditable execcommand

使所选文字变为粗体:

document.execCommand('bold', null, null);

当用户再次选择该段文本(或其中的一部分)时,您怎么知道它已变为粗体?

Bold就是一个例子。 commandName可以是underlineheadingcreateLink,...

2 个答案:

答案 0 :(得分:12)

document.queryCommandState
     

确定是否已对当前执行给定命令   选择。

来源:http://blog.whatwg.org/the-road-to-html-5-contenteditable#how

显然我搜索得不够好。

答案 1 :(得分:0)

你会知道它是大胆的,因为它被<b></b>标签包裹着。 (或用户代理用于粗体文本的任何内容)

相关问题