Want to change data member value in javascript

I have a javascript prototype like this.

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

I want to change the defaultTab value from another function. There I used.

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

Warning gives me a screenshot enter image description here . And the meaning does not change. Can anyone help me find a problem.

+4
source share
2 answers

I found a solution

 TabbedPanels1['defaultTab'].value 

Here it shows the meaning, and I set it that way.

 TabbedPanels1['defaultTab'].value = 1; 

He works.

+1
source

The problem is that you change the value of the property after executing the code to select the appropriate element.

You should do something similar to this:

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

And then you can change the tab using the function ...

 var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1"); TabbedPanels1.setDefaultTab(1); alert(TabbedPanels1.defaultTab); 
0
source

Source: https://habr.com/ru/post/1486643/


All Articles