[英]Google Closure: How do I setVisible on an Element
While rendering the page first time I create a toolbar using goog.ui.Toolbar
. 第一次渲染页面时,我使用goog.ui.Toolbar
创建了一个工具栏。 I later add some buttons to it. 稍后,我向其中添加一些按钮。 Also I hide a few buttons. 我也隐藏了一些按钮。
this.mainToolbar = new components.ui.Toolbar();
this.addChild(this.mainToolbar);
var mlSelectBtn = new components.ui.ToolbarButton(content);
mlSelectBtn.setId("select");
this.mainToolbar.addChild(mlSelectBtn, true);
var mlUnSelectBtn = new components.ui.ToolbarButton(content);
mlUnSelectBtn.setId("unselect");
this.mainToolbar.addChild(mlUnSelectBtn, true);
mlUnSelectBtn.setVisible(false);
Now when I click a few other buttons on my application I want to hide select button and unhide unselect button. 现在,当我在应用程序上单击其他几个按钮时,我想隐藏选择按钮并取消隐藏取消选择按钮。 I try to do this 我尝试这样做
var temp = document.querySelector("[id=unselect]");
temp.setVisible(true);
I get an error saying setVisible is not a function. 我收到一个错误消息,说setVisible不是一个函数。 How do I set the visible back to true ? 如何将visible设置为true?
The result of the querySelector
method is a DOM element, but to call setVisible
you need a reference to the ToolbarButton
( mlUnSelectBtn
, above). querySelector
方法的结果是一个DOM元素,但是要调用setVisible
您需要引用ToolbarButton
(上面的mlUnSelectBtn
)。 You will need to store a reference to mlUnSelectBtn
somewhere which can be accessed by the code which resets the visibility. 您将需要存储对mlUnSelectBtn
的引用,该引用可以通过重置可见性的代码进行访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.