开发者

How to capture checkbox click event?

I am using jstree and trying to capture a checkbox state change event. How do I get the currently selected checkbox's state and its 开发者_开发问答list id?

The example that I found here: Jquery Jstree checkbox events capture works but I cannot figure out how to get the node's check state. If there is a better or simpler way, I am open to other suggestions.

$("#demo1").bind("change_state.jstree", function (e, d) {
        if ((d.args[0].tagName == "A" || d.args[0].tagName == "INS") &&
            (d.inst.data.core.refreshing != true && d.inst.data.core.refreshing != "undefined")) 
        {
            //if a checkbox or it's text was clicked, 
            //and this is not due to a refresh or initial load, run this code . . .
            alert("list id: " +d.rslt.attr("id"));
            alert("is item checked?" +"***TODO***"); 
        }
    });

Thanks.

**EDIT: I made my question clearer to avoid any confusion about combining plugins (this is not what I'm doing). I have enabled the tree checkboxes within jstree. **


Not a Solution, a work around!!! I found this post looking for a solution to a similar problem, after playing with various scenarios decided not to use the

real_checkboxes

option. Instead I added a series of hidden checkboxes of my own and modified your script to set the checked status of the hidden boxes, which then get posted back to the server (MVC3) in the form. I can then use the id of the tree node LI to set the checked status of my check boxes.

if ((d.args[0].tagName == "A" || d.args[0].tagName == "INS") &&
        (d.inst.data.core.refreshing != true && d.inst.data.core.refreshing != "undefined")) {
            //if a checkbox or it's text was clicked, 
            //and this is not due to a refresh or initial load, run this code . . .
            var id = d.rslt.attr("id"); 
            var checked = $("#" + id + ".jstree-checked").length!=0; // use the length!=0 to get a bool of the checked status
            $("#log").append("list id: " + id);
            $("#log").append("is item checked ? " + checked);
            $("#log").append("<br/>");


        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜