Ext.select('input[id^=radio]')得到的对象添加事件参数已经不是Ext的radio对象看了下源代码,这样获取到的参数是通过http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.EventManager-method-on添加的,对应的参数为handler : Function The handler function the event invokes.Parameters event : Ext.EventObject The EventObject describing the event. target : Ext.dom.Element The Element which was the target of the event. Note that this may be filtered by using the delegate option. options : Object The options object from the addListener call. Ext不怎么用,都是活学活用。。 Ext.select('input[id^=radio]').on('focus', function (event, target, options) { //event为事件对象 alert(target == this)//target和this为同一个对象,为DOM对象,因为是直接从dom对象生成的Ext对象 });
console.log(ev.target.boxLabel);
});
console.log(radio.boxLabel);
});
anel.items.each(function () { this.on('focus', function () {console.log(this) }); })
<head>
<link rel="stylesheet" type="text/css" href="./ExtJS4/resources/css/ext-all.css" />
<script type="text/javascript" src="./ExtJS4/ext-all.js"></script>
<script type="text/javascript">
Ext.onReady(function() {
var panel = new Ext.Panel({
renderTo : 'panel',
frame : true,
width : 80,
height : 120,
title : 'Radio',
items : [ {
id : 'radio1',
xtype : 'radio',
boxLabel : '选项一',
name : 'radio',
inputValue : '1',
checked : true
}, {
id : 'radio2',
xtype : 'radio',
boxLabel : '选项二',
name : 'radio',
inputValue : '2'
}, {
id : 'radio3',
xtype : 'radio',
boxLabel : '选项三',
name : 'radio',
inputValue : '3'
} ]
});
Ext.select('input[id^=radio]').on('focus', function(radio, e, eOpts) {
console.log(radio.target instanceof Ext.Component);
console.log(radio.target instanceof Ext.dom.Element);
console.log(radio.target instanceof Ext.CompositeElement);
console.log(radio.boxLabel);
});
});
</script>
</head>
<body>
<div id="panel"></div>
</body>
</html>上面大哥说select返回的是Element类型,我查API说的是Ext.CompositeElement类型,但是我上面的例子输出的是
false
false
false
undefined
所以我也弄不清传入监听函数里的是什么类型了
The handler function the event invokes.Parameters
event : Ext.EventObject
The EventObject describing the event.
target : Ext.dom.Element
The Element which was the target of the event. Note that this may be filtered by using the delegate option.
options : Object
The options object from the addListener call.
Ext不怎么用,都是活学活用。。 Ext.select('input[id^=radio]').on('focus', function (event, target, options) {
//event为事件对象
alert(target == this)//target和this为同一个对象,为DOM对象,因为是直接从dom对象生成的Ext对象
});
addListener: function(eventName, handler, scope, opt) {
var els = this.elements,
len = els.length,
i, e; for (i = 0; i < len; i++) {
e = els[i];
if (e) {
Ext.EventManager.on(e, eventName, handler, scope || e, opt);////////////
}
}
return this;
}