Three methods for writing Ext. button click events

Source: Internet
Author: User

The extjs writing method is too flexible. Now we have collected three methods for writing button click events. Make a record today for future reference.
First, create a JS file and write the following code:
1. Click handler by default.
Ext. onready (function (){

New Ext. Button ({
Text: "OK ",
// Draw the button in the body
Renderto: Ext. getbody (),
// Button width
Minwidth: 100,
ID: "mybutton"
// Click an event
Handler: function (){
Ext. MessageBox. Show ({
Title: 'hup ',
MSG: 'You clicked on me! ',
Buttons: Ext. MessageBox. OK,
FN: function (){},
Icon: Ext. MessageBox. Info
});
}
});
});

2. Add a listening method to listen to click events. Note that the listeners should not be less than S.
Ext. onready (function (){

New Ext. Button ({
Text: "OK"
// Draw the button in the body
Renderto: Ext. getbody (),
// Button width
Minwidth: 100,
ID: "mybutton ",
// Click an event
Listeners :{
"Click": function (){
Ext. MessageBox. Show ({
Title: 'hup ',
MSG: 'You clicked on me! ',
Buttons: Ext. MessageBox. OK,
FN: function (){},
Icon: Ext. MessageBox. Info
});
}
}
});
});

3. If you develop multiple components and need to interact with each other, you may need to write the events out to achieve loose coupling.
The code in JS is as follows:
Ext. onready (function (){

New Ext. Button ({
Text: "OK"
// Draw the button in the body
Renderto: Ext. getbody (),
// Button width
Minwidth: 100,
ID: "mybutton"
});
});

The webpage code is as follows:
<SCRIPT type = "text/JavaScript">

Ext. onready (function (){
// Obtain the component
VaR BTN = ext. getcmp ("mybutton ");
// Bind a click event
BTN. On ("click", function (){
Ext. MessageBox. Show ({
Title: 'hup ',
MSG: 'You clicked on me! ',
Buttons: Ext. MessageBox. OK,
FN: function (){},
Icon: Ext. MessageBox. Info
});
});
});

</SCRIPT>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.