如何让 YUI 编辑器传递其内容

How to get YUI editor to pass its contents

本文关键字:编辑器 YUI      更新时间:2023-09-26

我试图在asp mvc站点上使用YUI富文本编辑器 我使用此javascript代码

var myEditor = new YAHOO.widget.Editor('Body', {
    height: '300px',
    width: '522px',
    dompath: true, //Turns on the bar at the bottom
    animate: true //Animates the opening, closing and moving of Editor windows
});
myEditor.render();

''

在此文本区域

<div class="yui-skin-sam">
            @Html.TextAreaFor(model => model.Body, new { cols = "50", rows = 10 })
            @Html.ValidationMessageFor(model => model.Body)
        </div>

编辑器加载,但当我提交表单时,其内容未传递,我不断收到一条验证消息,说该字段是必需的,如果其中没有任何内容,我应该这样做。

有谁知道我如何让它按照我想要的方式工作?

如果其他人最终遇到此问题,这是解决方案。

你可以尝试像这样设置 handleSubmit:true

var myEditor = new YAHOO.widget.Editor('Body', {
height: '300px',
width: '522px',
dompath: true, //Turns on the bar at the bottom
animate: true, //Animates the opening, closing and moving of Editor windows
handleSubmit: true

});myEditor.render();

编辑器将尝试附加自身并自动调用我的myEditor.saveHTML(),它将内容填充回文本区域。如果它像我一样失败,请通过设置如下所示的事件来手动执行此操作。

   YAHOO.util.Event.on('somebutton', 'click', function() {
myEditor.saveHTML();
alert("test");
});

其中某个按钮是表单的提交按钮的名称。

当你开始工作时,你将遇到的第二个问题是 asp.net 当它在模型中找到html标签时会出错。这是一个不同的问题,所以我不会在这里描述解决方案。