将内容从<textarea>传递到api控制器

时间:2016-12-29 14:59:17

标签: javascript jquery html twitter-bootstrap ckeditor

&lt; p&gt;我正在尝试将内容从表单(在模态中)传递到api_controller。但我无法从我的&lt; code&gt;&lt; textarea&gt;&lt; / code&gt; ...中获取文字,即使只是简单的&lt; strong&gt;提示&lt; / strong&gt;&lt; / p&gt; &lt; p&gt; //简单的HTML-BOOTSTRAP表单 &lt; div class =“snippet”data-lang =“js”data-hide =“false”data-console =“true”data-babel =“false”&gt; &lt; div class =“snippet-code”&gt; &lt; pre class =“snippet-code-html lang-html prettyprint-override”&gt;&lt; code&gt;&lt; div class =“modal-dialog modal65resp”&gt;     &lt; div class =“modal-content”&gt;         &lt;! - modal-header - &gt;         &lt; div class =“modal-header”&gt;             &lt; h4&gt;新文件&lt; / h4&gt;         &LT; / DIV&GT;         &lt;! - modal-body - &gt;         &lt; div class =“modal-body”&gt;             &lt; form id =“newfileform”class =“form-horizo​​ntal”&gt;                 &lt;! - filename - &gt;                 &lt; div class =“form-group”&gt;                     &lt; label for =“filename”class =“col-sm-2 control-label”&gt; FileName:&lt; / label&gt;                     &lt; div class =“col-sm-10”&gt;                         &lt; input name =“filename”type =“text”class =“form-control”id =“filename”placeholder =“FileName”&gt;                     &LT; / DIV&GT;                 &LT; / DIV&GT;                 &lt;! - TxtArea - &gt;                 &lt; div class =“form-group”&gt;                     &lt; label for =“txtarea1”class =“col-sm-2 control-label”&gt; Text:&lt; / label&gt;                     &lt; div class =“col-sm-10”&gt;                         &lt; textarea type =“text”name =“txtarea1”id =“txtarea1”&gt;&lt; / textarea&gt;                     &LT; / DIV&GT;                 &LT; / DIV&GT;                 &lt;! - apath - &gt;                 &lt; div class =“form-group”&gt;                     &lt; label for =“apath”class =“col-sm-2 control-label”&gt;绝对路径:&lt; / label&gt;                     &lt; div class =“col-sm-10”&gt;                         &lt; input name =“savepath”type =“text”class =“form-control”id =“savepath”placeholder =“Absolute Path”readonly&gt;                     &LT; / DIV&GT;                 &LT; / DIV&GT;             &LT; /形式&GT;         &LT; / DIV&GT;         &lt;! - modal-footer - &gt;         &lt; div class =“modal-footer”&gt;             &lt; div class =“pull-left”&gt;                 &lt; div id =“info”&gt;&lt; / div&gt;             &LT; / DIV&GT;             &lt; div class =“pull-right”&gt;                 &lt; a class =“btn btn-default”data-dismiss =“modal”&gt;取消&lt; / a&gt;                 &lt; a class =“btn btn-success”onclick =“SaveFile()”&gt;保存文件&lt; / a&gt;             &LT; / DIV&GT;         &LT; / DIV&GT;     &LT; / DIV&GT; &LT; / DIV&GT;&LT; /代码&GT;&LT; /预&GT; &LT; / DIV&GT; &LT; / DIV&GT; &LT; / p为H. &lt; p&gt;这是我正在尝试使用CKEditor处理textarea的脚本。&lt; / p&gt; &LT; p为H. //脚本&LT; / p为H. &LT;预&GT;&LT;代码&GT;&LT;脚本&GT;     CKEDITOR.replace( 'txtarea1'); &LT; /脚本&GT; &LT;脚本&GT;     功能SaveFile()     {         var path = $('#savepath')。val()         var filename = $('#filename')。val()         var content = $('#txtarea1')。val()         警报(内容);     } &LT; /脚本&GT; &LT; /代码&GT;&LT; /预&GT;

1 个答案:

答案 0 :(得分:0)

您可以使用CKEDITOR.instances.txtarea1访问您的CKEDITOR实例,并使用getData获取HTML:

CKEDITOR.instances.txtarea1.getData();