简体   繁体   English

在FireFox中document.execCommand怪异的结果

[英]document.execCommand weird results in FireFox

WYSIWYG text format function 所见即所得文本格式功能

/*
 * myEditor - iframe element
 */
function doFormat(what) {

    var cWin = $('#myEditor', window.parent.document)[0].contentWindow; 

    cWin.$('body').attr({ 'contentEditable': true, 'designMode': 'On'} );

    var what = 'justifyright';

    cWin.document.execCommand(what, false, arguments[2]);

    cWin.$('body').attr({'contentEditable': 'false'} );
    return;
}

HTML: HTML:

<span id="obj_123" contenteditable="true"> 
    text<br /> 
    moretext<br /> 
    alot of text <br /> 
</span>

If clicked or highlighted PART (only if part selected) of the span contents and called function doFormat (with any justify function) 如果单击或突出显示了跨度内容的PART(仅在选择了Part的情况下),并调用了函数doFormat(带有任何对正函数)

the results are: 结果是:

<span id="obj_123" contenteditable="true"> 
    text<br /> 
</span>

<div align="right">
    <span id="obj_123" contenteditable="true">
        moretext<br /> 
    </span>
</div>

<span id="obj_123" contenteditable="true">
    alot of text <br /> 
</span>

expected results: 预期成绩:

<span id="obj_123" contenteditable="true"> 
    text<br /> 

    <div align="right">
        moretext<br /> 
    </div>
    alot of text <br /> 
</span>

as if it copies the parent node and then replicates it each time when formatting occures. 就像它先复制父节点,然后在每次格式化时复制它。

other execCommand calls like bold/italic/underline etc works as supposed. 其他execCommand调用(如粗体/斜体/下划线等)按预期工作。

I would appreciate any help on this topic. 我希望在这个主题上有任何帮助。 Thank you very much. 非常感谢你。

edit: added a fiddle test case http://jsfiddle.net/n7SgJ/ 编辑:添加了一个小提琴测试用例http://jsfiddle.net/n7SgJ/

Turns out this happens only if the rich text wrapper is a SPAN tag. 事实证明,仅当富文本包装器是SPAN标记时才会发生这种情况。 Everything works if DIV tag is used. 如果使用DIV标签,则一切正常。

Is there a reasonable explanation for this? 有合理的解释吗?

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

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