Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 焦点上的CKEditor删除默认值_Javascript_Ckeditor - Fatal编程技术网

Javascript 焦点上的CKEditor删除默认值

Javascript 焦点上的CKEditor删除默认值,javascript,ckeditor,Javascript,Ckeditor,对于一个普通的输入字段,我可以编写如下代码,当我单击时,它将删除输入字段的默认值,如果我没有在输入字段中写入任何内容,那么当我离开输入字段时,默认值将返回 jQuery('input[type="text"]').focus(function() { if (this.value == this.defaultValue) { this.value = ''; } if(this.value != t

对于一个普通的输入字段,我可以编写如下代码,当我单击时,它将删除输入字段的默认值,如果我没有在输入字段中写入任何内容,那么当我离开输入字段时,默认值将返回

jQuery('input[type="text"]').focus(function()
    {
        if (this.value == this.defaultValue)
        {
            this.value = '';
        }
        if(this.value != this.defaultValue)
        {
            this.select();
        }
    });

    jQuery('input[type="text"]').blur(function()
    {
        if (this.value == '')
        {
            this.value = this.defaultValue;
        }
    });
但我不知道如何使用CKEditor实现这一点。。我能得到一些帮助吗

我找到了这段代码,当我在编辑器中单击时会发出警报。但我不知道如何修改它,使其按我需要的方式工作

CKEDITOR.instances['post_content'].on('focus', function()
{
    alert(1);
});
你试过这个吗

CKEDITOR.instances['post_content'].on('focus', function()
{
    if (this.value == defaultValue)
    {
        this.value = '';
    }
});

将上述观点与[另一篇SO文章][1]相结合:

// delete default text on focus
CKEDITOR.instances['editor1'].on('focus', function () {

    var defaultText = '<p class=\"ckNormal\">Type your comment here</p>';
    var currentText = CKEDITOR.instances.editor1.getData();

    // debug - removed
    // alert(defaultText + '\n' + currentText);

    if (defaultText.trim()==currentText.trim()) {
        CKEDITOR.instances.editor1.setData('');
    }
});
//删除焦点上的默认文本
CKEDITOR.instances['editor1'].on('focus',function()){
var defaultText='

在此处键入您的注释

; var currentText=CKEDITOR.instances.editor1.getData(); //调试-删除 //警报(defaultText+'\n'+currentText); 如果(defaultText.trim()==currentText.trim()){ CKEDITOR.instances.editor1.setData(“”); } });

您可能不需要在测试之前修剪文本。这将使用getData查找文本内容,并使用setData对其进行更改。

This.value对我来说是未定义的