Home >Web Front-end >JS Tutorial >JQuery Easyui Tree's oncheck event implementation code_jquery

JQuery Easyui Tree's oncheck event implementation code_jquery

WBOY
WBOYOriginal
2016-05-16 18:26:131322browse

JQuery Easyui Tree's oncheck event implementation code_jquery


Using firebug to check the generated HTML, I found that the checkobx is fake, just a span, changing the style back and forth, sweat

JQuery Easyui Tree's oncheck event implementation code_jquery


Copy code 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 look at its onClick event script
Code
Copy 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 its check script accordingly
Copy the code 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() {//gzl increase
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 });
}
});

But I couldn’t get the Data value, and finally I had to $(this).parent().click(), click event plus check to determine whether it becomes selected, two The event uses one method, ugh
I really hope that a new version will be released, or that some expert will change it, my ability is too limited.
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn