Сегодня впервые столкнулся с YUI 2 Rich Text Editor
. (http://developer.yahoo.com/yui/editor/)
В основном я использую Java Server Pages для своих веб-сайтов.
Я хочу иметь возможность установить текст в текстовой области редактора на ранее отправленное значение. Например, когда пользователь отправляет страницу после ввода текста в редакторе, этот текст может быть сохранен в базе данных для использования в будущем. Затем я вызывал значение из базы данных и устанавливал редактор для отображения его в этот момент, чтобы пользователь мог вносить изменения.
Я нашел метод в документации 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>