我正在基于jQuery小部件创建一个富文本编辑器,并且它可以在页面上有多个实例。第一个实例应该生成这样的工具栏:
第二个实例应该生成:
也许问题归结为:我如何在小部件的命名空间中存储变量?
<input type="checkbox" id="bold-1"><label for="bold-1">..
<input type="checkbox" id="italic-1"><label for="italic-1">..
...
第二个实例应该生成:
<input type="checkbox" id="bold-2"><label for ="bold-2">..
<input type="checkbox" id="italic-2"><label for ="italic-2">..
像这样的东西可能有效,但我不喜欢在全局命名空间中存储计数器:
var textEditorCount;
$.widget("myEditor.textEditor", {
_create: function () {
textEditorCount = textEditorCount ? textEditorCount + 1 : 1;
this.instanceID = textEditorCount;
},
...
};
也许问题归结为:我如何在小部件的命名空间中存储变量?