extjs中的事件監聽方法
阿新 • • 發佈:2019-01-07
事件監聽方法:
(1) 這個方法主要給dom物件來監聽事件
Ext.get(document).on('事件',function(){ 處理方法});
(2)寫在容器裡面 如panel
listeners{'事件',function(){處理方法}};
(3)對定義的js類進行事件監聽
var eastpanel=new Ext.Panel({
region:'east',
collapsible: true,
width: 275,
items: [{....}]
});
eastPanel.on("collapse",function(e){
alert("ssad");
舉例:
如何給表單的textfield新增鍵盤監聽事件:
var searchKey = new Ext.form.TextField({ //text
id: 'searchkey',
fieldLabel: 'text',
name: 'text',
defaultType: 'textfield',
grow: false,
blankText: "這個欄位最好不要為空",
enableKeyEvents: true
});
searchKey.on('keypress', function(e){
// 監聽回車按鍵
if (e.getKey() == e.ENTER && this.getValue().length > 0) {
alert("OK");}
});
(1) 這個方法主要給dom物件來監聽事件
Ext.get(document).on('事件',function(){ 處理方法});
(2)寫在容器裡面 如panel
listeners{'事件',function(){處理方法}};
(3)對定義的js類進行事件監聽
var eastpanel=new Ext.Panel({
region:'east',
collapsible: true,
width: 275,
items: [{....}]
});
eastPanel.on("collapse",function(e){
alert("ssad");
});
(4)假設有個型別為GridPanel的變數gridPanel
gridPanel.addListener('rowclick',function(){
alert(3)}
);
舉例:
如何給表單的textfield新增鍵盤監聽事件:
var searchKey = new Ext.form.TextField({ //text
id: 'searchkey',
fieldLabel: 'text',
name: 'text',
defaultType: 'textfield',
grow: false,
blankText: "這個欄位最好不要為空",
enableKeyEvents: true
});
searchKey.on('keypress', function(e){
// 監聽回車按鍵
if (e.getKey() == e.ENTER && this.getValue().length > 0) {
alert("OK");}
});