带有表单提交的htmlbox帖子值

时间:2011-03-14 20:05:42

标签: jquery html plugins post

我正在使用htmlbox jquery插件, 如果我在输入一些文本但未使用任何工具栏按钮时提交表单,则提交旧数据而不是新编辑的文本。 当我首先点击工具栏按钮(例如,使一些文本变为粗体)时,正在提交新文本。

我看到插件有get_html和get_text函数:我应该在提交之前首先查询wysiwygeditor还是还有其他我缺少的东西?

插件网站上给出的示例使用自定义提交方法,我更喜欢没有控制器方法服务器端(asp mvc)仅用于发布一个文本字段,我更喜欢使用常规<input type=submit ..>

编辑:这可以解决方法但只是感觉不对

$('#form').submit(function() { (hb.val(hb.get_html())); });

1 个答案:

答案 0 :(得分:0)

要使用HtmlBox的内置函数,请执行以下操作: 将htmlbox()的返回值分配给变量,然后使用该变量调用HtmlBox的方法(例如hb_full.get_html();或任何其他方法)。请参阅下面的代码示例。

<script type="text/javascript">
    var hb_full;
$(document).ready(function(){
        hb_full = $("#htmlbox_full").css("height", "300").css("width", "100%").htmlbox({
            toolbars: [
                [
                    // Cut, Copy, Paste
                    "separator", "cut", "copy", "paste",
                    // Undo, Redo
                    "separator", "undo", "redo",
                    // Bold, Italic, Underline, Strikethrough, Sup, Sub
                    "separator", "bold", "italic", "underline", "strike", "sup", "sub",
                    // Left, Right, Center, Justify
                    "separator", "justify", "left", "center", "right",
                    // Ordered List, Unordered List, Indent, Outdent
                    "separator", "ol", "ul", "indent", "outdent",
                    // Hyperlink, Remove Hyperlink, Image
                    "separator", "link", "unlink", "image"
                ],
                [
                    // Show code
                    "separator", "code",
                            // Formats, Font size, Font family, Font color, Font, Background
                    "separator", "formats", "fontsize", "fontfamily",
                    "separator", "fontcolor", "highlight",
                ],
                [
                    //Strip tags
                    "separator", "removeformat", "striptags", "hr", "paragraph",
                    // Styles, Source code syntax buttons
                    "separator", "quote", "styles", "syntax"
                ]
            ],
            about: true, // "false" to hide About button
            idir: "./img/HtmlBoxImg/",
            icons: "default", //all options: "default", "silk"
            skin: "blue"      //all options: "silver", "blue", "green", "red"
        });
    });

    function getHtmlFromEditor()
    {
        var HtmlFromEditor = hb_full.get_html();
        alert(HtmlFromEditor);
    }
    </script>

    <textarea id="htmlbox_full"></textarea>
<button onclick="getHtmlFromEditor();">Display HTML</button>