admin管理员组文章数量:1305375
I want to read if a certain text in a contenteditable element is bold or not. In Chrome document.queryCommandValue("bold")
returns "true"/"false"
as a string, IE returns a true/false
as a boolean, but Firefox returns (empty string)
in the developer console.
I made a fiddle as an example: /
If you write som text in the div, mark it and then hit "Bold" the span should show "true"/"false"
or true/false
. I don't really care if its as a string or a boolean as I can convert it later.
I want to read if a certain text in a contenteditable element is bold or not. In Chrome document.queryCommandValue("bold")
returns "true"/"false"
as a string, IE returns a true/false
as a boolean, but Firefox returns (empty string)
in the developer console.
I made a fiddle as an example: http://jsfiddle/nTQd2/
If you write som text in the div, mark it and then hit "Bold" the span should show "true"/"false"
or true/false
. I don't really care if its as a string or a boolean as I can convert it later.
2 Answers
Reset to default 10For bold, italic and similar, use document.queryCommandState()
. Use document.queryCommandValue()
for non-Boolean mands.
http://jsfiddle/nTQd2/1/
That's simple.
Document.queryCommandValue()
returns a string. Instead of that use this.
Document.queryCommandState('Bold')
This will return a boolean value as true/false.
Example:
function isSelectedTextBold()
{
var isBold = document.queryCommandState("Bold");
return isBold;
}
I am also specifying function calls for other formatting options.
- Italic -> document.queryCommandState("Italic");
- Underline -> document.queryCommandState("Underline");
- Left Justify -> document.queryCommandState("justifyLeft");
- Center Justify -> document.queryCommandState("justifyCenter");
- Right Justify -> document.queryCommandState("justifyRight");
I hope this helps. :)
本文标签: javascriptdocumentqueryCommandValue returns (empty string) in FirefoxStack Overflow
版权声明:本文标题:javascript - document.queryCommandValue returns (empty string) in Firefox - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741804072a2398394.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论