gpt4 book ai didi

javascript - 如何在页面加载后将焦点设置到 good.ui.Component 或 goog.uiControl 子类组件?

转载 作者:行者123 更新时间:2023-11-30 13:21:33 26 4
gpt4 key购买 nike

我制作了这样的自定义组件:

my.Cmp = function(opt_domHelper) {
goog.ui.Component.call(this, opt_domHelper);

...

};
goog.inherits(my.Stamina, goog.ui.Component);

my.Cmp.prototype.createDom = function() {
this.decorateInternal(this.dom_.createDom('div', 'сmp-inner-div'));
};

my.Cmp.prototype.decorateInternal = function(element) {
my.Cmp.superClass_.decorateInternal.call(this, element);
var elem = this.getElement();

...

};

my.Cmp.prototype.disposeInternal = function() {
my.Stamina.superClass_.disposeInternal.call(this);

...

};

my.Cmp.prototype.enterDocument = function() {
...
}

my.Cmp.prototype.exitDocument = function() {
...
}

然后我在html文档中创建了一个实例

var cmp = new my.Cmp();
cmp.render(goog.dom.getElement('cmpContainerDivId'));

此组件使用键盘。单击鼠标后它获得键盘焦点并且工作正常。我找不到如何在页面加载后给予 kb 焦点。我试图从 goog.ui.Control 继承 my.Cmp 组件并使用它的 setFocused 方法。 getState() 显示焦点在集合中,但在单击鼠标或按下 Tab 键之前​​对 kb 键入没有反应。

最佳答案

据推测,具有以下内容:

my.Comp.prototype.setFocused = function(focused) {
goog.base(this, 'setFocused', focused);
if (focused) this.getElement().focus();
};

// ...

goog.events.listen(goog.dom.getWindow(), goog.events.EventType.LOAD, function() {
// ... other init
theCmp.setFocused(true);
});

setFocused() 似乎主要用于簿记,例如 isFocused() 和类似的状态方法。

关于javascript - 如何在页面加载后将焦点设置到 good.ui.Component 或 goog.uiControl 子类组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10096950/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com