使用 JQuery 设置 CKEditor 值
我有一个 CKEditor 文本区域:
<textarea cols="80" id="taBody" name="taBody" class="ckeditor" rows="10" runat="server"></textarea>
我有 jQuery 尝试设置数据库中的值:
$('#ContentPlaceHolder_taBody').val(substr[5]);
不要担心我已经测试过它返回字符串的子字符串。出于测试目的,我用“test”替换了子字符串,并收到了相同的问题。
我知道该行周围的 jquery 不会影响它,因为我试图填充的其他文本字段起作用。就说到ckeditor了。
以下是整个脚本:
function (obj) {
$.ajax({
type: "POST",
url: "ContentSections.aspx/GetContentDetails",
data: '{"nodeID": "' + obj.attr('id') + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var str = msg.d;
var substr = str.split('|||');
$('#ContentPlaceHolder_hfContentSectionID').val(substr[0]);
$('.txtAlias').val(substr[1]);
$('.txtBrowserTitle').val(substr[2]);
$('.txtMetaDescription').val(substr[3]);
$('.txtMetaKeywords').val(substr[4]);
$('#ContentPlaceHolder_taBody').val(substr[5]);
}
});
}
问题是没有填充任何内容,也没有显示 javascript 错误。
我尝试四处阅读,但找不到任何对我有帮助的东西。有人有什么想法吗?
I have a CKEditor textarea:
<textarea cols="80" id="taBody" name="taBody" class="ckeditor" rows="10" runat="server"></textarea>
I have jQuery trying to set the value from the database:
$('#ContentPlaceHolder_taBody').val(substr[5]);
Don't worry about the substring I already tested that it is returning a string. For testing purposes I replaced the substring with 'test' and was receiving the same issue.
I know that the jquery surrounding this line doesn't affect it because the other textfields I'm trying to populate work. Just when it comes to the ckeditor.
Here is the script in whole:
function (obj) {
$.ajax({
type: "POST",
url: "ContentSections.aspx/GetContentDetails",
data: '{"nodeID": "' + obj.attr('id') + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
var str = msg.d;
var substr = str.split('|||');
$('#ContentPlaceHolder_hfContentSectionID').val(substr[0]);
$('.txtAlias').val(substr[1]);
$('.txtBrowserTitle').val(substr[2]);
$('.txtMetaDescription').val(substr[3]);
$('.txtMetaKeywords').val(substr[4]);
$('#ContentPlaceHolder_taBody').val(substr[5]);
}
});
}
The issue was that nothing was being populated and no javascript errors were being shown.
I tried to read around but couldn't find anything that helped me. Does anyone have any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要使用 CKEditor 的 API 来代替。
具体来说, http://docs.cksource.com/ckeditor_api/符号/CKEDITOR.editor.html#setData
You need to use CKEditor's API instead.
Specifically, http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setData
阅读此链接后 http://docs.cksource.com/ckeditor_api/symbols /CKEDITOR.editor.html#setData,以下代码对我有用。
After reading this link http://docs.cksource.com/ckeditor_api/symbols/CKEDITOR.editor.html#setData, following code work for me.
其中 value 就像你想要设置的 html 数据
where value is like you want set html data