9

所以我想做的是使用jQuery的AJAX函数提交一个表单。我选择走的路线是使用 $('#form').serialize(); 然后将其作为 GET 请求传递。在我添加将在网站上使用的编辑器 NicEdit 之前,它的效果非常好。

我已经研究过这个问题,情况是一旦 NicEdit 接管了一个文本区域,它就会向用户隐藏文本区域,而是让她写入 . 然后,这些数据将被放回由按下普通提交按钮触发的文本区域。

现在的问题是:我没有正常的提交按钮,因此不会触发将数据放回文本区域的事件。我已经尽力 解决这个问题谷歌解决方案,但我发现的一切都一文不值。

鉴于我的情况的基本设置:http: //jsfiddle.net/MMzhS/1/ - 在 alert() 之前,您如何将数据从 NicEdit 表单获取到文本区域;叫做?

4

7 回答 7

24
var nicE = new nicEditors.findEditor('assignment');
question = nicE.getContent();

'assignment' 是您的文本区域 ID。

textarea 内容保存在问题变量中,希望这会有所帮助

于 2011-12-15T09:14:33.437 回答
12

#jQuery 中的 BinaryKitten 提供的以下内容相同,但在我看来更简洁:http: //jsfiddle.net/MMzhS/5/

于 2011-03-06T00:26:12.263 回答
4
  1. 创建一个 nicEdit 实例

    MyApp.editor = new nicEditor().panelInstance('texarea_id');

  2. 让用户随心所欲地输入内容!(无意的双关语)

  3. 获取内容:

    var content = MyApp.editor.instanceById('textarea_id').getContent();

  4. 像往常一样使用 发布内容content

于 2012-09-06T06:09:45.103 回答
3

var nicInstance = nicEditors.findEditor('options1'); var messageContent = nicInstance.getContent();

其中 options1 是 textarea 的 id

于 2015-10-30T10:48:09.737 回答
0
document.getElementById("content").value = "<html><head><title></title><head><body>"+nicEditors.findEditor("this will be your id of your textarea").getContent()+"</body></head></html>";
var templateContent = document.getElementById("content").value;
于 2011-03-25T11:54:43.860 回答
0
var data = $('#peter div').eq(90).text();

is the data's information. Also, please use $.post instead of $.get for form submissions; be nice to the internet.

于 2011-03-05T23:33:00.117 回答
0

对于想知道如何在 nicEdit 中添加自定义组合框的人,这是我的博客文章,用于显示带有动态值的自定义下拉列表

关联

通过编辑 NiceEdit js 文件,我们可以在 NicEdit 中添加自定义组合框

通过以下方式,我们可以将下拉菜单或组合框添加到 NicEdit。您可以通过 ajax 调用从数据库中获取下拉值并在 NicEdit 中显示它首先在 aspx 页面上下载并实现 NicEdit 下载 NiceEdit js 文件,您可以通过以下代码启用它(http://nicedit.com/

 <div style="height: 700px; width: 70%; overflow: scroll">                <div id="sample"><script type="text/javascript" src="../scripts/nicEdit.js"></script><script src="../nicExample/nicExample.js"></script>
                    <script type="text/javascript">
                        bkLib.onDomLoaded(function () {
                            //  nicEditors.allTextAreas()
                            new nicEditor({ fullPanel: true }).panelInstance('area2');});</script>
                    <h4>NicEdit Textarea</h4><textarea name="area2" id="area2" style="width: 70%; height: 700px"> </textarea>
                    </div></div>

现在在文件末尾的 niceEdit.js 文件中添加 getddlData() Ajax 函数

// AJAX call
function getddlData() {
    var ajaxResponse;
    $.ajax({
        type: "POST",
        url: 'NicEdit.aspx/GetBookMarkData', // AJAX call to fecth dropdown data
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        async: false,
        cache: false,
        // Text file name
        success: function (response) {
            //    //alert(data.d);    // or do some other data processing
            //   //return data.d;
            ajaxResponse = response;
        }
    });
    return ajaxResponse.d;
}

// 在代码隐藏(.cs 文件)中添加一个 webMethod 到 fetech 下拉值到 nicedit

   [WebMethod]
        public static string GetBookMarkData()
        {
///Also you can get DB's data here
            ///  (2 responses dropdown values being filled :  'drop down Value', drop down Text)
            /// Need DB data in , seprated list  Formate:  @@Test@@,TestOne, TestOne,  @@Test2@@,Test2,Test2
            string sbookmarkData = "<<Test_Name>>,Test Name,<<Test_Add>>,Test Add,<<Test_Location>>,Test Location,<<Test_City>>,Test City,<<Test_Phone>>,Test Phone";
            return sbookmarkData;
        }

现在打开 NicEdit js 文件并复制(第 1552 行)或搜索以下行:

var nicEditorFontFormatSelect = nicEditorSelect.extend({

Copy complete function and create another one by changing names etc

var nicEditorInsertBookmark = nicEditorSelect.extend({
    /* By Pankaj Sharma : Not Needed Now  */
    sel: {
        '[[Location]]': "Test Name",
        pre: "Test Address",
        h6: "Test City",
        h5: "Test State",
        h4: "Test Zip",
        h3: "Test ABC",
        h2: "Test One",

    },
    init: function () {
        /* Pankaj Sharma */
        this.setDisplay("Insert Bookmark");
        var response = getddlData();
        var responseArr = response.split(",");
        var strings = [];
        //for (itm in this.sel) {         
        //  //  var A = itm.toUpperCase();
        //    //this.add(  A,  this.sel[itm]  )
        //   }

        for (i = 0; i < responseArr.length; i++) {
            strings.push([responseArr[i], responseArr[i + 1]]);
            i = i + 1;
        }
        for (var i in strings) {
            this.add(strings[i][0], strings[i][1]);
        }
        /* END HERE*/
    },
});

转到第 1230 行或搜索以下行:

var nicSelectOptions = { 按钮:{ 在 fontFormat 函数下方添加以下内容

'CustomBookmark': { name: __('Insert Bookmark'), type: 'nicEditorInsertBookmark', // 命令:'InsertBookmark' //InsertBookmark }

现在更新的功能应该是这样的

var nicSelectOptions = {
    buttons: {
        'fontSize': {
            name: __('Select Font Size'),
            type: 'nicEditorFontSizeSelect',
            command: 'fontsize'
        },
        'fontFamily': {
            name: __('Select Font Family'),
            type: 'nicEditorFontFamilySelect',
            command: 'fontname'
        },
        'fontFormat': {
            name: __('Select Font Format'),
            type: 'nicEditorFontFormatSelect',
            command: 'formatBlock'
        },
        'CustomBookmark': {
            name: __('Insert Bookmark'),
            type: 'nicEditorInsertBookmark',  //
            command: 'InsertBookmark'   //InsertBookmark
        }
    }
};

现在转到第 1385 行或更新:function (A) { 将其更改为

 update: function (A) {
        //  alert(this.options.command);
        if (this.options.command == 'InsertBookmark') {+
 var editor = nicEditors.findEditor("area2");
        var range = editor.getRng();
        var editorField = editor.selElm();

            editorField.nodeValue = editorField.nodeValue.substring(0, range.startOffset) + A + editorField.nodeValue.substring(range.endOffset, editorField.nodeValue.length);
}
        else {
            // alert(A);  
            /* END HERE */
            this.ne.nicCommand(this.options.command, A);
        }
        this.close()
    }

在下拉选项上单击这将在光标位置的文本编辑器中添加下拉值。

END,你应该可以看到结果

于 2014-10-16T05:24:24.527 回答