javascript - ckeditor 未加载通过 ajax 调用生成的元素?

标签 javascript php jquery html ajax

我正在使用自定义表单并通过 ajax 调用生成表单元素,但 textarea 未使用 ckeditor 加载。这是我的代码:

ajax代码:

    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响应是:

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

html代码:

  <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

您的代码应如下所示:

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");

});

关于javascript - ckeditor 未加载通过 ajax 调用生成的元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23757388/

相关文章:

javascript - Selenium 中未加载外部 javascript

javascript - 无法使用 php 将文件上传到 Google Drive

jQuery 下拉菜单、选项卡可访问性

javascript - 使用ajax更改页面时重新初始化javascript函数

javascript - 全屏谷歌地图

javascript - D3 图形缺少与轴中刻度一样多的文本元素

javascript - 使用 youtube api 嵌入多个 iframe

php - PHP正则表达式用于不同的URL

php - 拉拉维尔 5.5 : Authorization with pivot table

jquery - Colorbox在内容完全加载后返回html