JQueryEasyuiTree oncheck event implementation code _ jquery

Source: Internet
Author: User
EasyuiTree has been used in recent projects. I want to select the checkbox event, but the api only provides one onClick event. After Baidu and google, I 'd like to read JavaScript.


View the html generated by firebug and find that the checkobx is fake. It is just a span, and it changes the style back and forth.


The Code is as follows:


$ (". Tree-checkbox", tree). unbind (". tree"). bind ("click. tree", function (){
If ($ (this). hasClass ("tree-checkbox0 ")){
$ (This). removeClass ("tree-checkbox0"). addClass ("tree-checkbox1 ");
} Else {
If ($ (this). hasClass ("tree-checkbox1 ")){
$ (This). removeClass ("tree-checkbox1"). addClass ("tree-checkbox0 ");
} Else {
If ($ (this). hasClass ("tree-checkbox2 ")){
$ (This). removeClass ("tree-checkbox2"). addClass ("tree-checkbox1 ");
}
}
}
_ 2eb ($ (this). parent ());
_ 2ec ($ (this). parent ());
Return false;
});


Then let's look at its onClick event script.
Code

The Code is as follows:


$ (". Tree-node", tree)
....
Bind ("click. tree", function (){
$ (". Tree-node-selected", tree). removeClass ("tree-node-selected ");
$ (This). addClass ("tree-node-selected ");
If (opts. onClick ){
Var _ 2ea = this;
Var data = $. data (this, "tree-node ");
Opts. onClick. call (this, {id: data. id, text: data. text, attributes: data. attributes, target: _ 2ea });
}
})


Modify the check script accordingly.

The Code is as follows:


$ (". Tree-checkbox", tree). unbind (". tree"). bind ("click. tree", function (){
If ($ (this). hasClass ("tree-checkbox0 ")){
$ (This). removeClass ("tree-checkbox0"). addClass ("tree-checkbox1 ");
} Else {
If ($ (this). hasClass ("tree-checkbox1 ")){
$ (This). removeClass ("tree-checkbox1"). addClass ("tree-checkbox0 ");
} Else {
If ($ (this). hasClass ("tree-checkbox2 ")){
$ (This). removeClass ("tree-checkbox2"). addClass ("tree-checkbox1 ");
}
}
}
_ 2eb ($ (this). parent ());
_ 2ec ($ (this). parent ());
Return false;
}). Bind ("click. tree", function () {// Add gzl
If ($ (this). hasClass ("tree-checkbox1") & opts. onCheck ){
Var _ 2e9 = this;
Var data = $. data (this, "tree-node ");
Opts. onCheck. call (this, {id: data. id, text: data. text, attributes: data. attributes, target: _ 2e9 });
}
});


However, we couldn't get the Data value, so we had to $ (this). parent (). click () at last. The click Event and check were changed to the selected one. We used one method for the two events.
I hope to release a new version, or which of the following experts will change the version. I can do it too much.
Related Article

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.