Yahoo YUI 2-Rich Text Editor-无法使setEditorHTML方法正常工作,这是怎么回事? [英] Yahoo YUI 2 - Rich Text Editor - can't get setEditorHTML method to work, what's wrong?
问题描述
今天,我第一次遇到了 YUI 2 Rich Text Editor
。 (http://developer.yahoo.com/yui/editor/)
Today, for the first time, I came across the YUI 2 Rich Text Editor
. (http://developer.yahoo.com/yui/editor/)
我主要将Java Server Pages用于我的网站。
I mainly use Java Server Pages for my websites.
我希望能够将编辑器的文本区域中的文本设置为先前提交的值。例如,当用户提交页面时,在编辑器中输入文本后,该文本可以保存在数据库中以备将来使用。然后,我将从数据库中调用该值,并将编辑器设置为此时显示它,以便用户可以进行修改。
I want to be able to set the text in the textarea of the Editor to a previously submitted value. As an example, when a user submits the page, after having entered text in the Editor, that text may be saved in a database for future use. I would then call the value from the database, and set the Editor to display it at that point, so the user could make modifications.
我在API中找到了一个方法名为 setEditorHTML()
的文档-但由于某种原因,我无法使其正常工作。
I found a method in the API documentation called setEditorHTML()
- but for some reason or another, I can't get it to work.
这是我一直在玩的测试代码。我正在Firefox中进行测试。
Here is the test code I've been playing around with. I'm testing in Firefox.
我不明白为什么 setEditorHTML
方法为什么不会工作...有人可以帮助我吗?
I don't understand why the setEditorHTML
method won't work...can someone please assist me?
<html>
<head>
<% String editorText = (String)session.getAttribute("editorText"); %>
<!-- Individual YUI CSS files -->
<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.9.0/build/assets/skins/sam/skin.css">
<!-- Individual YUI JS files -->
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/element/element-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/container/container_core-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/menu/menu-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/button/button-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/dragdrop/dragdrop-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/slider/slider-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/colorpicker/colorpicker-min.js"></script>
<script type="text/javascript" src="Yahoo-YUI-editor/editor-min.js"></script>
<script type="text/javascript" src="http://yui.yahooapis.com/2.9.0/build/layout/layout-min.js"></script>
<script language="javascript">
var myEditor = new YAHOO.widget.Editor('msgpost', {
height: '300px',
width: '522px',
dompath: false, //Turns on the bar at the bottom
animate: false, //Animates the opening, closing and moving of Editor windows
handleSubmit: true
});
myEditor.render();
<% if(editorText != null) {
out.print("myEditor.setEditorHTML(\""+editorText+"\");");
}
%>
</script>
</head>
<body class="yui-skin-sam">
<form name="editor" action="YahooEditor.jsp" method="post">
<textarea name="msgpost" id="msgpost" cols="50" rows="10"></textarea>
<input type="submit" value="submit"/>
</form>
</body>
</html>
推荐答案
编辑器有时会呈现您正在渲染的时间无法访问 setEditorHTML
。试试这个:
There is a time while the editor is rendering which you cannot access setEditorHTML
. Try this:
var myEditor = new YAHOO.widget.Editor('msgpost', {
height: '300px',
width: '522px',
dompath: false, //Turns on the bar at the bottom
animate: false, //Animates the opening, closing and moving of Editor windows
handleSubmit: true
});
myEditor.render();
// I just took a guess on which event to use here
myEditor.on('windowRender', function() {
myEditor.setEditorHTML("Hello World");
});
这是 YUI编辑器事件。
这篇关于Yahoo YUI 2-Rich Text Editor-无法使setEditorHTML方法正常工作,这是怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!