跨浏览器强/ em插入使用execCommand [英] Cross-browser strong/em insertion using execCommand

查看:111
本文介绍了跨浏览器强/ em插入使用execCommand的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 contentEditable 功能和 execCommand ,可以编辑/格式化页面某些部分的内容,就像在所有的WYSIWYG网络编辑器中使用的内容一样。但是,有许多浏览器与此类功能的实现不一致,导致此类网络编辑人员手动处理。

Using contentEditable feature and the execCommand, one can edit/format the content of certain parts of the page like what is used in all WYSIWYG web-editor. However, there are numerous browsers inconsistencies with the implementation of such feature, which have lead such web-editors to handle them manually.

在我的情况下,IE使用 斜体命令的 em 元素,这正是我想要的, >强和 em ,而不是视觉样式的 b , 。但是,其他浏览器使用这些视觉样式元素,并且不提供设置 em 元素的方法。

In my case, IE uses strong and em elements for the Bold and Italic commands, which is exactly what I want as I am after the semantic strong and em, and not the visual-style ones of b, i, and/or styled span. However, other browsers uses those visual-style elements, and don't provide a way to set a strong or em elements.

有什么方法可以在所有浏览器中使用 strong em 吗?
不介意添加新的命令来处理这样的事情,只要它实现了IE的近似结果。此外,很好能够将它们应用到相交的内联/块元素,而不破坏浏览器(或至少以相等的方式打破它们)。是的,我可以使用一些其他编辑器,但我只对这个功能感兴趣。

Is there is a way to make it possible to use strong and em in all the browsers? I don't mind adding new commands to handle such thing as long as it achieve an approximate results to the IE ones. Also, it would be nice to be able to apply them to intersecting inline/block elements without breaking the browsers (or at least breaking them in an equal manner). Yes, I can use some of the other editors, but I am interested in this feature only. I would appreciate any help.

谢谢

推荐答案

正是你的意思,因为我刚刚碰到同样的问题。通过搜索真的很难在这里是我认为有帮助(StackOverflow中的链接):

I know exactly what you mean because I just ran into the same problem. By searching really hard here is something I think helps (a link in StackOverflow):

Using contentEditable in Firefox: 'bold' renders correctly, but html code is incorrect

在这里看到它,在execCommand('bold')之前添加以下行:

To see it here, it says, adding the following line before execCommand('bold'):

document.execCommand('StyleWithCSS', false, false);

我尝试并修复它,在Firefox 13.0.1中插入一个(在此之前,FF插入 font-weight:bold)。我现在很兴奋。

I tried and it fixed it, inserting a in Firefox 13.0.1 (before this, FF inserted "font-weight:bold"). I'm quite excited now.

这篇关于跨浏览器强/ em插入使用execCommand的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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