Cannot convert dynamically loaded teaxtarea into ckeditor

只谈情不闲聊 提交于 2019-12-25 03:17:08

问题


calling this get_content function after clicking a link.

function get_content(n)
{
    var hr=new XMLHttpRequest();
    var url="./updatecontent.php";
    var vars="id="+n;
    hr.open("POST",url,true);
    hr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    hr.onreadystatechange=function()
    {
        if(hr.readyState==4 && hr.status==200)
        {
            var return_data=hr.responseText;
            document.getElementById("content").innerHTML=return_data;
        }
    }
    hr.send(vars);
    document.getElementById("content").innerHTML='<img src="./img/loading.gif">';
}

<div id="content"></div>

The following is the response data

<div id="text-editor" style="width:100%;">
<form action="" method="post">
<textarea class="ckeditor" name="editor1" id="txt1"></textarea>
<input type="submit" name="update" value="Update">
</form>
</div>
<script  src="./ckeditor/ckeditor.js"></script>

The response data is succefully added to div id="content"

The relative link to ckeditor is correct.But the textarea is not converting into CKeditor. where is the mistake? please help.


回答1:


In this case you need to call CKEDITOR.replace('editor1') after content being changed.

So in your case it will be

function get_content(n)
{
    var hr=new XMLHttpRequest();
    var url="./updatecontent.php";
    var vars="id="+n;
    hr.open("POST",url,true);
    hr.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    hr.onreadystatechange=function()
    {
        if(hr.readyState==4 && hr.status==200)
        {
            var return_data=hr.responseText;
            document.getElementById("content").innerHTML=return_data;
            CKEDITOR.replace('editor1'); // <-- add this line
        }
    }
    hr.send(vars);
    document.getElementById("content").innerHTML='<img src="./img/loading.gif">';
}


来源:https://stackoverflow.com/questions/19988754/cannot-convert-dynamically-loaded-teaxtarea-into-ckeditor

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!