如何知道哪个UI元素焦点 [英] how to know which UI element is in focus
问题描述
我有一个文本框的eventhandler函数,它执行以下操作:
- 搜索用户的联系人并显示联系人匹配文本框的
模式
对于另外两个文本框应该完成相同的功能。由于文本框的值是使用e.parameter.textbox1NAME获得的,因此我添加了两个更多的函数作为事件处理函数,
textbox2.addKeyUpHandler('search2');
textbox3.addKeyUpHandler('search3');
除了
textbox1.addKeyUpHandler( '搜索1');
这三个函数唯一的区别是所用的模式是
e。 parameter.textbox1NAME或e.parameter.textbox2NAME或e.parameter.textbox3NAME
我认为这样效率低下,有什么办法可以知道哪个元素会调用处理程序或哪个元素处于焦点?
谢谢
解决方案斯洛克答案非常聪明!我喜欢它,并想尝试一下...这是一个例子来说明!
function multitext_test(){
var app = UiApp.createApplication()。setHeight('150')。setWidth('200');
app.setTitle(测试这些文本框);
var panel = app.createFlowPanel();
var txt1 = app.createTextBox()。setName('txt1')。setId('txt1');
var txt2 = app.createTextBox()。setName('txt2')。setId('txt2');
var txt3 = app.createTextBox()。setName('txt3')。setId('txt3');
var label = app.createLabel('type in any textBoxBox')。setId('label')
app.add(panel.add(txt1).add(txt2).add(txt3 )。新增(标签));
var QHandler = app.createServerHandler(key)。addCallbackElement(panel);
txt1.addKeyUpHandler(QHandler);
txt2.addKeyUpHandler(QHandler);
txt3.addKeyUpHandler(QHandler);
//
var doc = SpreadsheetApp.getActive();
doc.show(app);
}
//
功能键(e){
var app = UiApp.getActiveApplication();
var src = e.parameter.source;
var newValue = e.parameter [src];
var act = app.getElementById(src)
label = app.getElementById('label')
label.setText(您在textBox nr中输入''+ newValue +''+ src .substring(3));
act.setStyleAttribute('background','yellow');
返回应用程序
}
I have an eventhandler function for a textbox, that does the following,
- Searches the contacts of the user and displays, the contacts that matches the pattern of the textbox
The same function should be done for two more textboxes.
Since the value of the textbox is obtained using "e.parameter.textbox1NAME", I have added two more functions as event handlers,
textbox2.addKeyUpHandler('search2'); textbox3.addKeyUpHandler('search3');
in addition to
textbox1.addKeyUpHandler('search1');
The only difference among the three functions is whether the pattern used is, "e.parameter.textbox1NAME" or "e.parameter.textbox2NAME" or "e.parameter.textbox3NAME"
I think this is inefficient, is there any way to know which element invokes the handler or which element is in focus? Thanks
解决方案Srik answer is very smart ! I liked it and wanted to give it a try... here is an example to illustrate !
function multitext_test() { var app = UiApp.createApplication().setHeight('150').setWidth('200'); app.setTitle("test these textboxes"); var panel = app.createFlowPanel(); var txt1 = app.createTextBox().setName('txt1').setId('txt1'); var txt2 = app.createTextBox().setName('txt2').setId('txt2'); var txt3 = app.createTextBox().setName('txt3').setId('txt3'); var label = app.createLabel('type in any of these textBoxes').setId('label') app.add(panel.add(txt1).add(txt2).add(txt3).add(label)); var QHandler = app.createServerHandler("key").addCallbackElement(panel); txt1.addKeyUpHandler(QHandler); txt2.addKeyUpHandler(QHandler); txt3.addKeyUpHandler(QHandler); // var doc = SpreadsheetApp.getActive(); doc.show(app); } // function key(e){ var app = UiApp.getActiveApplication(); var src = e.parameter.source; var newValue = e.parameter[src]; var act= app.getElementById(src) label = app.getElementById('label') label.setText("You typed '"+newValue+"' in textBox nr "+src.substring(3)); act.setStyleAttribute('background','yellow'); return app }
这篇关于如何知道哪个UI元素焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!