我正在使用自定义表单并通过 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/