在通过ajax提交时如何获取nicEdit表单的内容?

所以我想要做的是使用jQuery的AJAX函数提交表单。 我选择的路线是使用$(’#form’)。serialize(); 然后将其作为GET请求传递。 它解决了所有花花公子,精细和花花公子,直到我添加编辑器NicEdit,我将在网站上使用。

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

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

考虑到我的情况基本设置: http : //jsfiddle.net/MMzhS/1/ – 如何在alert()之前将NicEdit表单中的数据提供给文本区域; 叫做?

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

‘assignment’是你的textarea id。

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

来自#jQuery的BinaryKitten提供的以下内容相同但在我看来更清晰: http : //jsfiddle.net/MMzhS/5/

  1. 创建一个nicEdit实例

    MyApp.editor = new nicEditor()。panelInstance(’texarea_id’);

  2. 让用户输入内容到他们内心的内容! (双关语无意)

  3. 获取内容:

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

  4. 使用content照常发布content

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

其中options1是textarea的id

 var data = $('#peter div').eq(90).text(); 

是数据的信息。 另外,请使用$.post而不是$.get来提交表单; 对互联网很好。

 document.getElementById("content").value = ""+nicEditors.findEditor("this will be your id of your textarea").getContent()+""; var templateContent = document.getElementById("content").value; 

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

链接

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

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

  

NicEdit Textarea

现在在文件末尾的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 Add,<>,Test Location,<>,Test City,<>,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 = {buttons:{在fontFormat函数下面添加以下内容

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

现在更新的function应该是这样的

 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() } 

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

END,你应该能看到结果