今天,我第一次遇到了YUI 2 Rich Text Editor
。 (http://developer.yahoo.com/yui/editor/)
我主要为我的网站使用Java Server Pages。
我希望能够将编辑器的textarea中的文本设置为先前提交的值。例如,当用户提交页面时,在编辑器中输入文本后,该文本可以保存在数据库中以备将来使用。然后,我将调用数据库中的值,并将编辑器设置为在该点显示,以便用户进行修改。
我在API文档中找到了一个名为setEditorHTML()
的方法 - 但由于某种原因,我无法让它工作。
这是我一直在玩的测试代码。我在Firefox中测试。
我不明白为什么setEditorHTML
方法不起作用...有人可以帮我吗?
<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>
答案 0 :(得分:3)
编辑器渲染时有一段时间您无法访问setEditorHTML
。试试这个:
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 Editor events的列表。