本文介绍了在对象名称中使用Javascript变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用CKEditor,当引用CKEditor实例时,我需要使用一个变量。但是,由于调用实例是一个对象,我真的不知道该如何做。
我使用:
CKEDITOR.instances.textarea123.insertHtml('< p> Whatever< / p>');
问题是,我需要123是一个变量,因为我需要更改实例基于
那么,如何在对象名称中使用变量?
由于显而易见的原因,以下不工作,但我需要实现它是假装做: var id = 354;
CKEDITOR.instances.textarea + id + .insertHtml('< p> Whatever< / p>');
解决方案
请尝试以下操作:
var id = 354;
CKEDITOR.instances ['textarea'+ id] .insertHtml('< p> Whatever< / p>');
I am using CKEditor, and, when referring to the CKEditor instance, I need to use a variable. But, since calling the instance is a object, I am really not sure how to do this.
I am using:
CKEDITOR.instances.textarea123.insertHtml('<p>Whatever</p>');
The issue is, I need 123 to be a variable, because I need to change the instance based on the editor page that is loaded.
So, how can I use a variable in an object name?
For obvious reasons the following does not work, but I need to achieve what it is "pretending" to do:
var id = 354;
CKEDITOR.instances.textarea+id+.insertHtml('<p>Whatever</p>');
解决方案
Try the following:
var id = 354;
CKEDITOR.instances['textarea'+id].insertHtml('<p>Whatever</p>');
这篇关于在对象名称中使用Javascript变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!