document.queryCommandValue在Firefox中返回(空字符串) [英] document.queryCommandValue returns (empty string) in Firefox

查看:1051
本文介绍了document.queryCommandValue在Firefox中返回(空字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果contenteditable元素中的某个文本是粗体或不粗体,我想阅读。在Chrome document.queryCommandValue(bold)中返回true/false一个 true / false 作为布尔值,但Firefox在开发者控制台中返回(空字符串)



我以小提琴为例:
http:// jsfiddle .net / nTQd2 /



如果您在div中编写som文本,请将其标记为粗体,跨度应显示true/false true / false 。我真的不关心它是一个字符串还是一个布尔值,因为我可以稍后进行转换。 为粗体,斜体和类似的,使用 文档.queryCommandState() 。对于非布尔命令使用 document.queryCommandValue()



http://jsfiddle.net/nTQd2/1/


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.net/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.

解决方案

For bold, italic and similar, use document.queryCommandState(). Use document.queryCommandValue() for non-Boolean commands.

http://jsfiddle.net/nTQd2/1/

这篇关于document.queryCommandValue在Firefox中返回(空字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆