在Django框架中使用jQuery获取CKEditor值 [英] Get CKEditor value using Jquery in django framework

查看:38
本文介绍了在Django框架中使用jQuery获取CKEditor值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用CkEditor for Django,并且我有一个包含3个字段的表单,一个产品代码,一个主题和一个正文.前两个字段是普通字段,而主体字段是CKEditor字段,该字段正从forms.py呈现在模板上.为了对此数据进行ajax调用,我需要使用Jquery来获取CkEditor内容.这该怎么做?到目前为止,这是我的代码.

I'm using CkEditor for Django and I have a form with 3 fields, a product code, a subject and a body. The first two fields are normal fields and the body field is a CKEditor field that is being rendered on the template from forms.py. In order to do an ajax call on this data, I need to use Jquery to get the CkEditor content. How to do this? This is my code so far.

我的模板:

form action="." method="post">    
    {{form2.as_p}}
    {% csrf_token %}
    <br><button name="form_submit"  id="email_submit" type="submit" class="btn btn-primary" value="send_email">Submit</button>
</form>

我的表格:

class CustomersWhoBoughtForm(forms.Form):
    product_code = forms.CharField(required=True,  max_length=1000, label='Product Code')
    subject = forms.CharField(required=True, max_length=1000,  label='Email Subject')
    body = forms.CharField(widget=CKEditorUploadingWidget(config_name='default')) #trying to get value of this field for Ajax Call

我尝试过:

var product_id= $('#id_product_code').val();   //This works
var subject = $('#id_subject').val();          //Also works
var body = $('#id_body').val();                //Does not work, neither does ck_id_body

推荐答案

这个问题与django或python无关.纯粹是关于如何从CkEditor中获取内容的信息,如果您进行搜索,则将有大量关于此主题的答案.

This question nothing to do with django or python. It is pure about how to get the content from CkEditor and if you search there will be tons of answers on this topic.

以下是获取编辑器内容的方法:

Here is how you can get the content of the editor:

var value = CKEDITOR.instances['id_body'].getData()

这篇关于在Django框架中使用jQuery获取CKEditor值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆