execCommand的替代品 [英] Alternatives to execCommand

查看:1590
本文介绍了execCommand的替代品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻求创建一个所见即所得的编辑器,使用jQuery作为框架,从中我可以使用不同的方法来简化生产.

I'm looking to create a WYSIWYG editor, using jQuery as a framework from which I can use different methods to ease production.

目前我确实有一位在职的编辑,而且运作良好.我使用一个iFrame,并将其designMode设置为on并从那里开始.但是,有些事情困扰着我.

I do actually have a working editor at the moment, and it's working well. I use an iFrame, and set it's designMode to on and go from there. However there are a few things which are nagging me.

以更改所选文本的字体系列为例.目前,我正在使用这个:

Take as an example changing the font family of the selected text. At the moment I am using this:

editorDoc.execCommand('fontname', false, 'verdana');

…现在工作正常:它可以在iFrame中正确显示更改.但是,当我实际查看代码时(我将iFrame中的任何代码复制到隐藏的输入中,然后发布),都会产生

…now that works fine: it shows the change correctly in the iFrame. However, when I actually look at the code (I copy any code inside the iFrame into a hidden input and then POST it) it produces

<font class="Apple-style-span" face="verdana">aasdf</font>

我意识到,Apple-style-span的第一流是Webkit的东西,没关系.困扰我的是<font>的全部用法.

I realise that the first class of Apple-style-span is a webkit thing, which doesn't matter. The thing which is nagging me is the whole use of <font>.

研究execCommand似乎不是一个标准,尽管大多数浏览器都支持它.它虽然很旧,所以我想知道是否有人听说过或知道一种更好的产生相同效果的方法,希望它能提供更多的语义代码产品.不仅限于iFrame,还可以使用<textarea>.

Researching the execCommand it looks like it's not a standard, although most browsers do support it. It is old though, so I was wondering if anyone had heard or know of a better method of producing the same effect, with hopefully a more semantic code product. It would also be fantastic not to be limited to a iFrame, but to be able to use a <textarea> instead..

非常感谢, 加雷斯(Gareth)

Many thanks in advance, Gareth

contentEditable是否可以帮助我实现不使用iFrame的目标?

Could contentEditable help me with my aim to not use an iFrame?

推荐答案

您可以使用常规DOM方法对iframe的DOM进行任何所需的操作.如果需要一些见解,请查看TinyMCE的来源.

You can do any manipulations you want with iframe's DOM using usual DOM methods. Look in the sources of TinyMCE if you need some insights.

这篇关于execCommand的替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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