javascript - 想要在 javascript 中更改数据成员的值

标签 javascript prototype

我有一个这样的 javascript 原型(prototype)。

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;
};

我想从另一个函数更改 defaultTab 的值。那里我用过。

var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1");

    alert(TabbedPanels1.defaultTab);
    TabbedPanels1.defaultTab=1;

警报给了我屏幕截图 enter image description here .而且值(value)没有改变。谁能帮我找出问题所在。

最佳答案

我找到了解决方案

TabbedPanels1['defaultTab'].value

这里是显示值,我通过这种方式设置为1。

TabbedPanels1['defaultTab'].value = 1;

它正在工作。

关于javascript - 想要在 javascript 中更改数据成员的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17150547/

相关文章:

javascript - 读取上一个 Prop : Too many renders

javascript - 类型错误 : Cannot set property <function> of undefined

javascript,原型(prototype)无法创建自己的方法

JavaScript:如何从数组中删除特定元素

javascript - Node 模块和原型(prototype)继承

javascript - 仅显示一台 toastr

javascript - 下拉菜单位于 bootstrap 3 的面板下

javascript - HTML5 视频全屏按钮

javascript - Jquery 效果Onunload

JavaScript 嵌套对象对父对象的引用