Php 无法使用fancybox键入CKeditor

Php 无法使用fancybox键入CKeditor,php,jquery,cakephp,ckeditor,fancybox,Php,Jquery,Cakephp,Ckeditor,Fancybox,这是我在cakephp项目中用于实现经过编辑的CKeditor版本的代码 <div style='display:none'> <div class="umsg_div" id="umsg_div"> <?php echo $this->Form->create('Inbox',array('action'=>'private_message_reply','id' =>

这是我在cakephp项目中用于实现经过编辑的CKeditor版本的代码

<div style='display:none'>
    <div class="umsg_div" id="umsg_div">
        <?php           
            echo $this->Form->create('Inbox',array('action'=>'private_message_reply','id' => 'form_umsg'));
        ?>

        <ul >           
            <?php echo $this->Form->input('Inbox.to_id',array('type'=>'hidden','value'=>@$message_details['Inbox']['from_id'],'id'=>'to_id')); ?>
            <li><div class="blue_title">Send Private Message</div></li><br/>
            <li>Subject</li>
            <li><?php echo $this->Form->input('Inbox.subject',array('type'=>'text','class'=>'subject','label'=>false));?></li><br/>
            <li>Message</li>
            <li>
                <?php echo $this->Form->input('Inbox.message',array('type' => 'textarea','id'=>'user_message','rows'=>"2",'style'=>'width:130%','label'=>false));?>
                <script language="javascript" type="text/javascript">
                    if (CKEDITOR.instances['user_message']) {                   
                        CKEDITOR.instances.user_message.destroy();
                     }
                     CKEDITOR.replace( 'user_message',{
                                toolbar : 'Basic',
                    });

                </script> 
            </li>
            <li style="text-align:right;padding:10px;"><input type="submit" name="umsg" value="Send" class="normal_button"/> or <a href="#" onclick='return hide_reply();'>Cancel</a></li>
        </ul>
        <?php echo $this->Form->end(); ?>   
    </div>
</div>

  • 发送私人信息

  • 主题

  • 信息
  • if(CKEDITOR.instances['user_message']){ CKEDITOR.instances.user_message.destroy(); } CKEDITOR.replace('user_message'{ 工具栏:“基本”, });

我在很多地方的项目中使用了ckeditor。。。但是在这里我不能输入文本字段。

问题可能是Fancybox克隆了您作为内容提供的内容,这意味着原始DOM元素的所有事件处理程序都丢失了。换句话说,如果您有一个HTML
元素,并且已经在其上注册了一个事件处理程序,如:

$(function(){
    $('#span-id').click(function(){
        alert('hello world!');
    });
});

你想在Fancybox中显示这个
,然后点击它,你将不会收到任何消息。

这只是前一张海报的延伸,他指出了由于Fancybox克隆内容而无法访问DOM元素:

一种选择是在Fancybox完成后附加它:

$("#stuff").fancybox({
            // [Your settings]
    onComplete : function() {
                // Register your CKeditor here
                if (CKEDITOR.instances['user_message']) {                   
                    CKEDITOR.instances.user_message.destroy();
                 }
                 CKEDITOR.replace( 'user_message',{
                            toolbar : 'Basic',
                });
    }
});
这可能有点黑客,作为免责声明,我从未使用过Fancybox。但以下是回调的API:


希望这有帮助。

基本上,DOM事件正在被覆盖,因此您需要做的是在后加载上使用setTimeout来解决问题:

$("#id_of_fancybox_thingy").fancybox({

    //all your existing stuff goes here...

    afterLoad:function(){
        setTimeout(function(){

            if (CKEDITOR.instances['elementname']) {
                CKEDITOR.instances['jelementname'].destroy();
                delete CKEDITOR.instances['elementname'];
            }
            CKEDITOR.replace('elementname', { "toolbar": [ [ "Cut", "Copy", "Paste", "PasteText", "PasteFromWord", "-", "Print" ], [ "Undo", "Redo", "-", "Find", "Replace", "-", "SelectAll", "RemoveFormat" ], [ "\/" ], [ "Bold", "Italic", "Underline", "Strike", "-", "Subscript", "Superscript" ], [ "NumberedList", "BulletedList", "-", "Outdent", "Indent", "Blockquote" ], [ "JustifyLeft", "JustifyCenter", "JustifyRight", "JustifyBlock" ], [ "Link", "Unlink", "Anchor" ], [ "\/" ], [ "TextColor", "BGColor" ], [ "Maximize", "ShowBlocks" ] ], "height": "200", "width": "690" });

        }, 1000);
    }

});

加载页面时会发生什么情况?该编辑器是否已初始化?你犯了什么错误?你试过使用firebug之类的调试工具吗?一切听起来都很清楚,但我无法在文本区域中键入..它似乎已被禁用或有什么问题..我正在使用另一个编辑器..谢谢你的尝试兄弟。让我们确实尝试一下..@jack你能告诉我你现在使用的是哪个编辑器吗?那个编辑解决了这个问题吗?