ckeditor的不加载上通过Ajax调用生成的元素?加载、元素、ckeditor、Ajax

2023-09-10 20:32:34 作者:你的床上人来人往好热闹

我使用自定义表单,并生成表单元素与AJAX调用,但textarea的是没装的CKEditor。这是我的code:

I am using custom form and generating form elements with ajax call but textarea is not loaded with ckeditor. Here is my code:

阿贾克斯code:

    jQuery.ajax({
    type: "POST",
    url: "reg_arz_ajax2.php",
    data: "book="+book_arzyabi,
    dataType : "html",
    success: function(response){

        $('#resp').html(response);
    },
    error:function (xhr, ajaxOptions, thrownError){
        //On error, we alert user
        alert(thrownError);
    }
});

$( "#dialog-form" ).dialog( "open");

});

Ajax响应是:

ajax response is:

   '<textarea class="ckeditor" cols="80" id="fname" name="fname" rows="10" >test</textarea>';

HTML code:

html code:

  <html>
 <head>
 <script type="text/javascript" src="../include/ckeditor/ckeditor.js"></script>
 <script type="text/javascript" src="../include/ckeditor/sample.js" ></script>
 </head>

 <body>
 <form>
 <fieldset>
 <label for="name">Name</label>
 <div id="resp" ></div>
 </fieldset>
 </form>
 </body>
 </html>

请帮我解决问题。

推荐答案

将这些行:

ckeditor.replace('#fname'); // ADD THIS
$('#fname').ckeditor(); // ADD THIS

您code应该是这样的:

Your code should look like this:

jQuery.ajax({
type: "POST",
url: "reg_arz_ajax2.php",
data: "book="+book_arzyabi,
dataType : "html",
success: function(response){

    $('#resp').html(response);
    ckeditor.replace('#fname'); // ADD THIS
    $('#fname').ckeditor(); // ADD THIS
},
error:function (xhr, ajaxOptions, thrownError){
    //On error, we alert user
    alert(thrownError);
}
});

$( "#dialog-form" ).dialog( "open");

});