javascript 如何将占位符属性添加到 CKEditor 的实例?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28301703/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I add a placeholder attribute to an instance of CKEditor?
提问by Mark
Right now, using Alfonso's plugin, I'm able to add the placeholder attribute in config.js. However, since I'm adding into config.js, that means all instances will have the same placeholder text, right?
现在,使用阿方索的插件,我可以在 config.js 中添加占位符属性。但是,由于我添加到 config.js 中,这意味着所有实例都将具有相同的占位符文本,对吗?
Well, I don't want all instances of my ckeditor to have the same placeholder text because I also noticed he also said :
好吧,我不希望我的 ckeditor 的所有实例都具有相同的占位符文本,因为我还注意到他还说:
The value can be set in the configuration or as an attribute of the replaced element
该值可以在配置中设置或作为被替换元素的属性
I figured this means that we can put "Type something..." as placeholder text for ckeditor1 and "Blabla..." as placeholder text for ckeditor2. How do I do that? Or that's not what he meant?
我认为这意味着我们可以将“键入内容...”作为 ckeditor1 的占位符文本,将“Blabla...”作为 ckeditor2 的占位符文本。我怎么做?还是他不是这个意思?
I have tried several ways including
我尝试了几种方法,包括
var ckeditor = CKEDITOR.replace('ckeditor1');
ckeditor.placeholder = 'Type sometheing....';
and
和
var config = [];
config['placeholder'] = 'some value'; //or config = [{placeholder:'some value'}]
CKEDITOR.replace("myeditor" , config );
inside that particular page but to no avail... I've also cleared my cache.
在该特定页面内,但无济于事......我也清除了我的缓存。
回答by AlfonsoML
By an attribute I meant:
通过一个属性,我的意思是:
<textarea name="editor" placeholder="Type here..."></textarea>
with regards to your other approaches, the configuration is an object, so this should work:
关于你的其他方法,配置是一个对象,所以这应该有效:
var config = {};
config.placeholder = 'some value';
CKEDITOR.replace("myeditor" , config );
回答by MJB
The CKEditor object has an attribute called instances
which stores all instances. To save an instance, you just add it to the instances
hash.
CKEditor 对象有一个名为的属性instances
,用于存储所有实例。要保存实例,只需将其添加到instances
哈希中即可。
var someDomElement = X;
CKEDITOR.replace(someDomElement);
CKEDITOR.instances[someDomElementId];
var someOtherDomElement = Y;
CKEDITOR.replace(someOtherDomElement);
CKEDITOR.instances[someOtherDomElementId];
Now you have two instances. You can now set or do anything to/with that instance with the standard API.
现在你有两个实例。您现在可以使用标准 API 对该实例进行设置或执行任何操作。
CKEDITOR.instances[someDomElementId].CKEDITOR_API()
回答by Jen
Something quick that might be helpful for others. I struggled getting this plugin work as well. The reason was I was using an old version of the plugin. I downloaded it from here: https://ckeditor.com/cke4/addon/confighelperand that page might confuse others too.
一些可能对其他人有帮助的快速方法。我也很难让这个插件工作。原因是我使用的是旧版本的插件。我从这里下载了它:https: //ckeditor.com/cke4/addon/confighelper,该页面也可能会让其他人感到困惑。
Almost all of the plugins from CKEditor show the most recent version on the top of the download list. Also when clicking the "Download" button it typically downloads the newest version of the plugin. That is not the case with this plugin. "Download" gets the oldest version and the oldest version is also listed first in the list.
几乎所有来自 CKEditor 的插件都会在下载列表的顶部显示最新版本。此外,当单击“下载”按钮时,它通常会下载插件的最新版本。这个插件不是这种情况。“下载”获取最旧的版本,最旧的版本也列在列表的最前面。
A "Gotcha" worth mentioning I think
我认为值得一提的“陷阱”
回答by Mackan
According to Alfonso's site the correct way would be:
根据阿方索的网站,正确的方法是:
config['placeholder'] = 'some value';
CKEDITOR.replace("myeditor" , config );