1

我正在尝试使用YUI2 Rich Text Editor,但似乎无法使其正常工作,无法保存和显示 textarea 的内容。在此先感谢您的帮助。

Javascript:

<script type="text/javascript">
var myEditor = new YAHOO.widget.Editor('msgpost', {
height: '80px',
width: '600px',
dompath: false, //Turns on the bar at the bottom
animate: true,
handleSubmit: false,
toolbar: {
titlebar: 'Comments:',
    buttons: [
        { group: 'textstyle', label: 'Font Style',
            buttons: [
                { type: 'push', label: 'Bold', value: 'bold' },
                { type: 'separator' },
                { type: 'push', label: 'Italic', value: 'italic' },
                { type: 'separator' },
                { type: 'push', label: 'Underline', value: 'underline' },
                { type: 'separator' },
                { type: 'push', label: 'Subscript', value: 'subscript', disabled: true },
                { type: 'separator' },
                { type: 'push', label: 'Superscript', value: 'superscript', disabled: true },

            ]
        },
        { type: 'separator' },
        { group: 'indentlist', label: 'Lists',
        buttons: [
        { type: 'push', label: 'Unordered List', value: 'insertunorderedlist' },
        { type: 'push', label: 'Ordered List', value: 'insertorderedlist' }
        ]
        }

    ]
}
});
myEditor.render();

//Inside an event handler after the Editor is rendered
YAHOO.util.Event.on('yuiButton', 'click', function() {
//Put the HTML back into the text area
myEditor.saveHTML();

//The var html will now have the contents of the textarea
var htmltest = myEditor.get('element').value;

document.getElementbyId("printHere").innerHTML = htmltest;
});
</script>

只是跟着yui tutorial, 并且只添加了以在withinnerHTML中显示文本编辑器中的内容divid="printHere"

HTML:

<body>
<form method="post" class="yui-skin-sam">
    <div class="yui-skin-sam">
        <textarea name="msgpost" id="msgpost" style="width: 600px; height: 80px;">
            A Commisioner has been commisioned
        </textarea>

    </div>
</form>
<input type="button" name="yuiButton" value="Save" />
<div id="printHere"></div>


</body>
4

0 回答 0