要更改javascript中数据成员的值吗
我有一个这样的javascript原型要更改javascript中数据成员的值吗,javascript,prototype,Javascript,Prototype,我有一个这样的javascript原型 Spry.Widget.TabbedPanels = function(element, opts) { this.element = this.getElement(element); this.defaultTab = 0; // Show the first panel by default. this.tabSelectedClass = "TabbedPanelsTabSelected"; this.tabHove
Spry.Widget.TabbedPanels = function(element, opts)
{
this.element = this.getElement(element);
this.defaultTab = 0; // Show the first panel by default.
this.tabSelectedClass = "TabbedPanelsTabSelected";
this.tabHoverClass = "TabbedPanelsTabHover";
this.tabFocusedClass = "TabbedPanelsTabFocused";
this.panelVisibleClass = "TabbedPanelsContentVisible";
this.focusElement = null;
this.hasFocus = false;
this.currentTabIndex = 0;
this.enableKeyboardNavigation = true;
this.nextPanelKeyCode = Spry.Widget.TabbedPanels.KEY_RIGHT;
this.previousPanelKeyCode = Spry.Widget.TabbedPanels.KEY_LEFT;
Spry.Widget.TabbedPanels.setOptions(this, opts);
// If the defaultTab is expressed as a number/index, convert
// it to an element.
if (typeof (this.defaultTab) == "number")
{
if (this.defaultTab < 0)
this.defaultTab = 0;
else
{
var count = this.getTabbedPanelCount();
if (this.defaultTab >= count)
this.defaultTab = (count > 1) ? (count - 1) : 0;
}
this.defaultTab = this.getTabs()[this.defaultTab];
}
// The defaultTab property is supposed to be the tab element for the tab content
// to show by default. The caller is allowed to pass in the element itself or the
// element's id, so we need to convert the current value to an element if necessary.
if (this.defaultTab)
this.defaultTab = this.getElement(this.defaultTab);
this.attachBehaviors();
};
Spry.Widget.TabbedPanels.prototype.getElement = function(ele)
{
if (ele && typeof ele == "string")
return document.getElementById(ele);
return ele;
};
警报给了我屏幕截图。而且这个值没有改变。有人能帮我找到问题吗。问题是,在执行代码以选择相应的元素后,您正在更改属性的值 您应该执行类似的操作:
Spry.Widget.TabbedPanels = function(element, opts)
{
this.element = this.getElement(element);
this.defaultTab = 0; // Show the first panel by default.
this.tabSelectedClass = "TabbedPanelsTabSelected";
this.tabHoverClass = "TabbedPanelsTabHover";
this.tabFocusedClass = "TabbedPanelsTabFocused";
this.panelVisibleClass = "TabbedPanelsContentVisible";
this.focusElement = null;
this.hasFocus = false;
this.currentTabIndex = 0;
this.enableKeyboardNavigation = true;
this.nextPanelKeyCode = Spry.Widget.TabbedPanels.KEY_RIGHT;
this.previousPanelKeyCode = Spry.Widget.TabbedPanels.KEY_LEFT;
Spry.Widget.TabbedPanels.setOptions(this, opts);
// If the defaultTab is expressed as a number/index, convert
// it to an element.
this.setDefaultTab = function(tab){
this.defaultTab = tab;
if (typeof (this.defaultTab) == "number")
{
if (this.defaultTab < 0)
this.defaultTab = 0;
else
{
var count = this.getTabbedPanelCount();
if (this.defaultTab >= count)
this.defaultTab = (count > 1) ? (count - 1) : 0;
}
this.defaultTab = this.getTabs()[this.defaultTab];
}
// The defaultTab property is supposed to be the tab element for the tab content
// to show by default. The caller is allowed to pass in the element itself or the
// element's id, so we need to convert the current value to an element if necessary.
if (this.defaultTab)
this.defaultTab = this.getElement(this.defaultTab);
}
this.setDefaultTab(this.defaultTab);
this.attachBehaviors();
};
Spry.Widget.TabbedPanels.prototype.getElement = function(ele)
{
if (ele && typeof ele == "string")
return document.getElementById(ele);
return ele;
};
我找到了解决办法
TabbedPanels1['defaultTab'].value
这里显示的是这个值,我通过这种方式将它设置为1
TabbedPanels1['defaultTab'].value = 1;
它正在工作。您的意思是执行分配后,
TabbedPanels1.defaultTab
的值不是1吗?您是如何确认这一点的?是的,它没有赋值。您是如何确定该值没有更改的?(请注意,在进行分配之前,您正在调用alert
。)这是为了更改html中选定的选项卡,而不是选择选项卡1。如果我从原型中分配值,它正在工作,但不是通过这个。要真正更改选项卡,您需要做的不仅仅是更改defaultTab
的值。请注意,构造函数在首次将其值设置为0后修改defaultTab
。(当构造函数调用attachBehaviors
时,可能会进一步使用defaultTab
),您需要在更改值时重复该处理;它不会完全自行发生。你应该把这个答案标记为你问题的答案。
TabbedPanels1['defaultTab'].value
TabbedPanels1['defaultTab'].value = 1;