简体   繁体   English

在Firefox中全选(ctrl + a)和document.execCommand问题

[英]Select all (ctrl + a) and document.execCommand problem in Firefox

I have a ribbon element of which text is editable. 我有一个可编辑文本的功能区元素。 It works fine, until you press ctrl + a or triple click inside to select all text in Firefox. 它可以正常工作,直到您按ctrl + a或在内部单击三次以选择Firefox中的所有文本。 document.execCommand won't work in Firefox with [Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: debugger eval code :: <TOP_LEVEL> :: line 1" data: no] error in console. document.execCommand在Firefox中无法使用[Exception... "Failure" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: debugger eval code :: <TOP_LEVEL> :: line 1" data: no]控制台错误。

To reproduce the problem, run the below code, select the entire text within element (by clicking the text and pressing ctrl + a) and in browser console run document.execCommand('italic'); 要重现该问题,请运行以下代码,在element中选择整个文本(单击文本并按ctrl + a),然后在浏览器控制台中运行document.execCommand('italic'); .

  <div style="position: absolute; top: 89px; left: 41px; z-index: 6;"> <font contenteditable="true" style=" float: left; background: #a64ba5; vertical-align: top; color: #fff; font-weight: bold; font-size: 12px; padding-left:10px; padding-top:14px; padding-bottom:14px; ">Some text</font> <span class="right" style=" position: absolute; content: ''; border: 20px solid #a64ba5; border-left-width: 10px; border-right-color: transparent;"></span> </div> 

Does anybody have any idea/fix to this problem? 是否有人对此问题有任何想法/解决办法?

I resolved the problem using div tag instead of font. 我使用div标签而不是字体解决了该问题。 This fixed the problem in Firefox, it seems to be Firefox bug. 这解决了Firefox中的问题,这似乎是Firefox错误。 Another option would be to put contenteditable attribute to parent element, but this break the element when you use ctrl + a and backspace. 另一个选择是将contenteditable属性放置到父元素,但是当您使用ctrl + a和backspace时,这会破坏元素。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM