jQuery Cleditor wysiwyg 文本编辑器:keyup() 适用于 webkit 浏览器,但不适用于 Firefox 或 IE
我正在尝试跟进之前的 Stackoverflow 问题,该问题涉及如何在外部 HTML 元素(例如
)中显示 Cleditor 文本框中的内容。这是问题和小提琴 解决了我在 webkit 浏览器中的问题,但不能解决 Firefox 或 IE 中的问题:
这是来自小提琴:
<textarea id="input" name="input"></textarea>
<p id="x"></p>
<script>
$("#input").cleditor();
$(".cleditorMain iframe").contents().find('body').bind('keyup',function(){
var v = $(this).text(); // or .html() if desired
$('#x').html(v);
});
</script>
我已经阅读了我需要的 从 jquery 获取 iframe 的内容使用“window.top ....访问主页并以这种方式传递它,因为并非所有浏览器都支持.contents()”,但我不确定如何使用window.top来实现此目的,并希望有人也许能够摆脱一些浅谈这个话题。
I'm trying to follow up on a previous Stackoverflow question about how to display content from a Cleditor textbox in an external HTML element such as a <p>
. Here's the question and the fiddle which solves my problem in webkit browsers but not Firefox or IE:
Here's the code from the fiddle:
<textarea id="input" name="input"></textarea>
<p id="x"></p>
<script>
$("#input").cleditor();
$(".cleditorMain iframe").contents().find('body').bind('keyup',function(){
var v = $(this).text(); // or .html() if desired
$('#x').html(v);
});
</script>
I've read Get content of iframe from jquery that I need to use "window.top.... to access the main page and pass it that way because .contents() is not supported by all browsers" but i'm not sure how to use window.top for this purpose and am hoping someone might be able to shed some light on this topic.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
cleditor 文档指出它确实有一个“change”事件,它声称可以与“keyup”事件一起使用,但不幸的是,在我的测试中,它在 Firefox 7 中没有按预期工作(需要单击文本编辑器) 。
Jsfiddle: http://jsfiddle.net/qm4G6/27/
代码:
还有另一个StackOverflow问题询问了同样的事情,其中用户 Ling 建议修改插件以添加您自己的功能:
从 jquery CLEditor 获取内容
编辑:
根据您对上述 SO 问题结果的评论不起作用,我修改了下面的代码。
这适用于 IE9 和 IE9 的“IE8”开发者模式。 http://jsfiddle.net/qm4G6/80/
另一个编辑:要获取 HTML,您必须在 iframe 中找到正文,例如
$(this).find("body").html()
。请参阅下面的代码。JSFiddle: http://jsfiddle.net/qm4G6/84/
The cleditor documentation states that it does have a "change" event which it claims to work with the 'keyup' event, but unfortunately in my testing it didn't work as expected with Firefox 7 (requires clicking out of the text-editor).
Jsfiddle: http://jsfiddle.net/qm4G6/27/
Code:
There is also another StackOverflow question which asked about the same thing, in which user Ling suggests modifying the plugin to add your own function:
Get content from jquery CLEditor
Edit:
Based on your comments with the above SO question result's not working, I've amended the code below.
This works in IE9 and IE9's "IE8" developer mode. http://jsfiddle.net/qm4G6/80/
Another Edit: To get the HTML, you have to find body within the iframe like
$(this).find("body").html()
. See the code below.JSFiddle: http://jsfiddle.net/qm4G6/84/
既然我回答了提示你这个问题的问题,我想我也会回答这个问题;)
适用于 Chrome 和 Firefox(我无法访问 IE):
这 net/qm4G6/26/" rel="nofollow">更新了 jsFiddle
更新
这也适用于 Chrome 和 Firefox。也许IE也可以?
jsFiddle
Since I answered the question that prompted you for this, I guess I'll answer this one too ;)
This works in Chrome and Firefox (I don't have access to IE):
Updated jsFiddle
UPDATE
This also works in Chrome and Firefox. Maybe IE too?
jsFiddle