你是用的ckeditor.net还是纯js的ckeditor

解决方案 »

  1.   

        for(var i=0;i<parseInt(num);i++)
               {   
                  if(CKEDITOR.instances["Encroll_Regulation_Label_Content_Content"+i])//判断是否绑定
                  {
                    CKEDITOR.remove(CKEDITOR.instances["Encroll_Regulation_Label_Content_Content"+i]); //解除绑定
                  }
                  CKEDITOR.replace("Encroll_Regulation_Label_Content_Content"+i);//重新绑定
               }  这是源码
      

  2.   

    if(CKEDITOR.instances["Encroll_Regulation_Label_Content_Content"+i])//判断是否绑定
      {
      CKEDITOR.instances["Encroll_Regulation_Label_Content_Content"+i].idestroy();  
    }
     
      

  3.   

    或者这样,删除了再移,ckeditor是有点小bug好象,remove后并没有真的干掉dom对象
    var ckobj=CKEDITOR.instances["Encroll_Regulation_Label_Content_Content"+i];
    if(ckobj)//判断是否绑定
      {
      ckobj.destroy();  
     ckobj=null;
    CKEDITOR.remove(ckobj);
    }
      

  4.   

    另外刚才我的
    CKEDITOR.instances["Encroll_Regulation_Label_Content_Content"+i].idestroy();
    写错了多了个i
    CKEDITOR.instances["Encroll_Regulation_Label_Content_Content"+i].destroy();
      

  5.   


    if(ckobj)//判断是否绑定
    这块有错
      

  6.   

    干脆你看下我最开头学ckeditor时写的测试页,有关自定义插件、纯静态网站相对路径处理的部分请自行略过。后台    public partial class hw_test_ckeditor : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                //得到的A_PAGE ID 
                string theID = "11111111";            string theCDEConfig = "var thefilebrowserUploadUrl = 'hw_test_ckeditor_upload.ashx?type=null'; \r\n";
                theCDEConfig = theCDEConfig + "var thefilebrowserImageUploadUrl = 'hw_test_ckeditor_upload.ashx?type=image'; \r\n";
                theCDEConfig = theCDEConfig + "var thefilebrowserFlashUploadUrl = 'hw_test_ckeditor_upload.ashx?type=flash'; \r\n";
                theCDEConfig = theCDEConfig + "var thefileContextUploadUrl = 'hw_test_ckeditor_context_upload.ashx'; \r\n";
                theCDEConfig = theCDEConfig + "var theAPageID = '" + theID + "'; \r\n";
                Page.ClientScript.RegisterClientScriptBlock(typeof(string), "theCKEditorValue", theCDEConfig, true);            Page.ClientScript.RegisterClientScriptInclude("getFilseJS", "hw_test_ckeditor_getfiles.ashx?id=" + theID);        }        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
            {
                TextBox1.Text = DropDownList1.SelectedValue;
                Button1.PostBackUrl = "/SITE_DATA_SOURCE/site1/subsite1/artlcleclass1/2011-0" + DropDownList1.SelectedValue + "/hw_test_ckeditor.aspx";
                string theJS = "window.onload = showCKEditor();";
                Page.ClientScript.RegisterClientScriptBlock(typeof(string), "theCKEditorEdit", theJS, true);
            }
    前台<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="hw_test_ckeditor.aspx.cs" Inherits="ITCOA_CMS.UI.hw_test_ckeditor" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
       <script type="text/javascript" src="CKEditor/ckeditor.js"></script>
       <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        a<br />
        a<br /> <a />
    <div id="CKEditorSpace"></div>
    <asp:TextBox ID="CKEditorContext" runat="server" TextMode="MultiLine" style="visibility:hidden; display:none;">adfafasfaf</asp:TextBox>
    <script type="text/javascript">
    var theCKEditor;
    function showCKEditor(){
        CKEDITOR.on('instanceReady', function(evt){
        
            var tempeditor = evt.editor;
            var themaximize = tempeditor.getCommand( 'maximize' );
            if(themaximize.state != CKEDITOR.TRISTATE_ON )
                tempeditor.execCommand('maximize');
        });    CKEDITOR.config.toolbar_itcoacmstb =
        [
            { name: 'document',    items : [ 'Source','-','SaveUp','NewPage','DocProps','Preview','Print','-','Templates' ] },
            { name: 'clipboard',   items : [ 'Cut','Copy','Paste','PasteText','PasteFromWord','-','Undo','Redo' ] },
            { name: 'editing',     items : [ 'Find','Replace','-','SelectAll','-','SpellChecker', 'Scayt' ] },
            { name: 'forms',       items : [ 'Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField' ] },
            '/',
            { name: 'basicstyles', items : [ 'Bold','Italic','Underline','Strike','Subscript','Superscript','-','RemoveFormat' ] },
            { name: 'paragraph',   items : [ 'NumberedList','BulletedList','-','Outdent','Indent','-','Blockquote','CreateDiv','-','JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock','-','BidiLtr','BidiRtl' ] },
            { name: 'links',       items : [ 'Link','Unlink','Anchor' ] },
            { name: 'insert',      items : [ 'Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak' ] },
            '/',
            { name: 'styles',      items : [ 'Styles','Format','Font','FontSize' ] },
            { name: 'colors',      items : [ 'TextColor','BGColor' ] },
            { name: 'tools',       items : [ 'Close', 'ShowBlocks','-','About' ] }
        ];    if(theCKEditor==null)
        {
            var theContextStr = document.getElementById("CKEditorContext").value;
            theContextStr = "";
            theCKEditor = CKEDITOR.appendTo('CKEditorSpace',{
                extraPlugins : 'itcoacms_close,itcoacms_save',
                toolbar : 'itcoacmstb',
    //            filebrowserBrowseUrl : '/ckfinder/ckfinder.html',
    //            filebrowserImageBrowseUrl : 'a_page_getfile.?type=Images',
    //            filebrowserFlashBrowseUrl : 'a_page_getfile.?type=Flash',
                filebrowserUploadUrl : thefilebrowserUploadUrl,
                filebrowserImageUploadUrl : thefilebrowserImageUploadUrl,
                filebrowserFlashUploadUrl : thefilebrowserFlashUploadUrl
            },theContextStr);
            
            addUploadButton(theCKEditor);
        }
    }function addUploadButton(theCKEditor){
        CKEDITOR.on('dialogDefinition', function( ev ){
            var dialogName = ev.data.name;
            var dialogDefinition = ev.data.definition;
            if ( dialogName == 'image' ){
                var infoTab = dialogDefinition.getContents( 'Upload' );
                infoTab.add({
                    type : 'select',
                    id : 'EX_select_image',
                    align : 'center',
                    label : '选择已有图片',
                    size: 5,
                    width: '150px',
                items : ArrayFiles,
                'default' : 'images1.jpg'
                }, ''); //place front of the browser button
                infoTab.add({
                    type : 'button',
                    id : 'EX_select_image_button',
                    align : 'center',
                    label : '选择',
                    onClick : function( evt ){
                        var thisDialog = this.getDialog();
                        var txtUrlObj = thisDialog.getContentElement('info', 'txtUrl');
                        var txtUrlObjID = txtUrlObj.getInputElement().$.id;
                        var urlObj = document.getElementById(txtUrlObjID);
                        var EX_select_imageObj = thisDialog.getContentElement('Upload', 'EX_select_image');
                        var EX_select_imageObjID = EX_select_imageObj.getInputElement().$.id;
                        var selectObj = document.getElementById(EX_select_imageObjID);
                        urlObj.value = selectObj.options[selectObj.selectedIndex].value;
                        urlObj.fireEvent("onchange"); //触发url文本框的onchange事件,以便预览图片
                    }
                }, ''); //place front of the browser button
            }
        });
    }function closeCKEditor(){
        if(theCKEditor!=null)
        {
            theCKEditor.destroy();
            theCKEditor = null;
        } 
    }</script>
    <%--<input type="button" value="edit" id="edit" onclick="javascript:showCKEditor();" />--%><input type="button" value="close" id="close" onclick="javascript:closeCKEditor();" />
    <asp:DropDownList  ID="DropDownList1" runat="server" AutoPostBack="true"   OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
    <asp:ListItem Value="1">1</asp:ListItem>
    <asp:ListItem Value="2">2</asp:ListItem>
    <asp:ListItem Value="3">3</asp:ListItem>
    </asp:DropDownList>
    <asp:Button ID="Button1" runat="server" Text="edit" PostBackUrl="~/hw_test_ckeditor.aspx" />
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        a<br />
        </div>
        </form>
    </body>
    </html>
      

  7.   

    我用Request.Form取值的时候取不到
      

  8.   

    我这个是脚本控制。。你这个是用服务器控件相当于刷新页面了。。那肯定没问题了。。而我没有进行刷新页面用的是ajax
      

  9.   

    提交前看下你的Encroll_Regulation_Label_Content_Content+i这个东西的值,另外我发现你用的replace绑定的ckeditor那么你的Encroll_Regulation_Label_Content_Content+i是个什么是个div吗?应该用appendto啊!这样才能把值传回绑定的text控件里。
      

  10.   

    提交前看下你的Encroll_Regulation_Label_Content_Content+i这个东西的值,另外我发现你用的replace绑定的ckeditor那么你的Encroll_Regulation_Label_Content_Content+i是个什么是个div吗?应该用appendto啊!这样才能把值传回绑定的text控件里。
      

  11.   

    Encroll_Regulation_Label_Content_Content+i 这个是多个文本域
    <textarea id=\"Encroll_Regulation_Label_Content_Content" + i + "\"  name=\"Encroll_Regulation_Label_Content_Content" + i + "\"  cols='20' rows='2'></textarea>
      

  12.   

    jQuery.getScript("/Public/ckeditor/ckeditor.js",function(){
                for(var i=0;i<parseInt(num);i++)
                   {   
                      CKEDITOR.replace("Encroll_Regulation_Label_Content_Content"+i);//重新绑定
                   }
               });
    简单吧!!!
    Page.ClientScript.RegisterClientScriptInclud("getFilseJS", "hw_test_ckeditor_getfiles.ashx?id=" + theID);
    我是看你这个想到的。。我重新加载一下脚本文件。。这样不管你绑定不绑定都清空了!
    你看是这个道理吗
      

  13.   

    耗费了我一天时间。。除了英文api没看之外,其他我全看了
      

  14.   

    非常奇怪你的情况,你看我的最简例子
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
       <script type="text/javascript" src="CKEditor/ckeditor.js"></script>
       <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
    </head>
    <body>
        <form id="form1" runat="server">
    <textarea cols="15" row="10" id="CKEditorSpace"></textarea>
    <textarea cols="15" row="10" id="CKEditorContext" >adfafasfaf</textarea>
    <script type="text/javascript">
    var theCKEditor;
    function showCKEditor(){
        theCKEditor = CKEDITOR.replace('CKEditorSpace');
    }
    function closeCKEditor(){
        if(theCKEditor!=null)
        {
            theCKEditor.destroy();
            theCKEditor = null;
        } 
    }
    </script>
    <input type="button" value="edit" id="edit" onclick="javascript:showCKEditor();" />
    <input type="button" value="close" id="close" onclick="javascript:closeCKEditor();" /></div>
    </form>
    </body>
    </html>
      

  15.   

    <textarea cols="15" row="10" id="CKEditorContext" >adfafasfaf</textarea>
    这行没用
      

  16.   

    来回replace都没问题几次都行。
      

  17.   

    不是。。咱们写的不是一个性质。。我是用ajax动态来加载的。。而且是多个。。而且每次切换都是多个。。而每次都是从0开始。。所以当第一次。。加载多个的时候就已经注册了Encroll_Regulation_Label_Content_Content0,Encroll_Regulation_Label_Content_Content1
    当下拉框变化的时候。又是另一个Encroll_Regulation_Label_Content_Content0,Encroll_Regulation_Label_Content_Content1
    第一次加载已经绑定进去了。。所以第二次再加载的话。。就有问题了,所以就要解除绑定。。然后再重新绑定
      

  18.   

    我取到了,你可以看到我textarea中值的变化。
      

  19.   

    所以我说,你在ajax提交前先看一下你的textarea中有没有内容,再看看你获取到了内容没有,你用chrome或firefox或ie下用httpwatch看一下,你post的ajax请求http头中有没有提交这些内容,也许你根本就没能成功获取内容就提交了。
      

  20.   

    我想你应该在ajax前看下textarea中有没有值,ajax获取到值没有,ajax发送了值没有。用chrome f12看,或ie 的httpwatch工具看ajax的http请求头,我怀疑你根本就没提交这些值。另外我的应用也是用的ajax提交的。下面是我扩展的ckeditor保存按钮代码,你可以看到我用了ajax(function(){
        // 按下自定义按钮时执行的代码
    var saveCmd =
    {
    exec : function( editor )
    {
        //Ajax上传内容
        var theHtml = editor.getData();
        var theTime = new Date();
        var theMarkStr = theTime.toString() + Math.random();
                var backhtml = $.ajax({
                  url: thefileContextUploadUrl,
                  data:{context : theHtml, apageid : theAPageID, str : theMarkStr},
                  async: false 
                }).responseText;
                if(backhtml == "OK")
                {
                    alert("保存成功!");
                }
                else
                {
                    alert("保存失败!");
                }   
    }
    }; var pluginName = 'itcoacms_save'; // Register a plugin named "itcoacms_save".
    CKEDITOR.plugins.add( pluginName,
    {
    init : function( editor )
    {
    var command = editor.addCommand( pluginName, saveCmd );
    editor.ui.addButton( 'SaveUp',
    {
                        label:'保存',
                        icon: this.path + 'icon.gif',
                        command: pluginName
    });
    }
    });
    })();
      

  21.   

    咱俩做的还是不一样我这个是用ajax加载编辑器。。然后用表单提交
     $.ajax({
                type:"post",
                url:"../Encroll/Encroll_do.aspx",
                data:"action=EncrollTable&state="+i,
                success:function(msg){
                    if(msg!=null && msg!=""){
                       
                        $("#frm_optitem_2").append(msg.split('$')[0]);
                        $("#Num").val(msg.split('$')[1]);
                        loadfck(msg.split('$')[1]);
                      }
                }
            })
      

  22.   

    msg.split('$')[0])这个就是多个文本域。。
    我还要进行清空。再加载
    $("#Encroll_Regulation_Type").change(function(){
                $("#frm_optitem_2 tr").remove();
                ajaxfck($(this).val());
                if($(this).val()=="-1")
                {
                    $("#frm_optitem_2").append("<tr><td><span style='color:Red'>是否选择了教育类型</span></td></tr>");
                }
            })
      

  23.   

    我擦我发现了个让人抓狂的事,你用textarea的话必须加上name属性后台才能获取到!
      

  24.   

    这样就没问题了,否则就是得不到!<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
       <script type="text/javascript" src="CKEditor/ckeditor.js"></script>
       <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
    </head>
    <body>
        <form id="form1" action="hw_test1.ashx" method="post">
    <textarea cols="15" row="10" id="CKEditorSpace" name="CKEditorSpace"></textarea>
    <script type="text/javascript">
    var theCKEditor;
    function showCKEditor(){
        theCKEditor = CKEDITOR.replace('CKEditorSpace');
    }
    function closeCKEditor(){
        if(theCKEditor!=null)
        {
            theCKEditor.destroy();
            theCKEditor = null;
        } 
    }
    </script>
    <input type="button" value="edit" id="edit" onclick="javascript:showCKEditor();" />
    <input type="button" value="close" id="close" onclick="javascript:closeCKEditor();" />
    <input type="submit" value="submit" id="submit" />
    </div>
    </form>
    </body>
    </html>
      

  25.   


    这个不是问题我所有的都带有name
      

  26.   


    这个不是问题我所有的都带有name