【问题标题】:How to capture checkbox click event?如何捕获复选框单击事件?
【发布时间】:2011-09-02 19:59:12
【问题描述】:

我正在使用 jstree 并尝试捕获复选框状态更改事件。如何获取当前选中复选框的状态及其列表 ID?

我在这里找到的示例: Jquery Jstree checkbox events capture 工作,但我不知道如何获得节点的检查状态。如果有更好或更简单的方法,我愿意接受其他建议。

$("#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***"); 
        }
    });

谢谢。

**编辑:我让我的问题更清楚,以避免对组合插件产生任何混淆(这不是我正在做的)。我在 jstree 中启用了树复选框。 **

【问题讨论】:

  • 您找到解决方案了吗?我面临同样的问题。请帮忙。

标签: jquery jstree


【解决方案1】:

不是解决方案,而是解决方法!!! 我发现这篇文章正在寻找类似问题的解决方案,在玩了各种场景后决定不使用

real_checkboxes

选项。相反,我添加了一系列我自己的隐藏复选框并修改了您的脚本以设置隐藏框的选中状态,然后以表单的形式将其发送回服务器(MVC3)。然后我可以使用树节点 LI 的 id 来设置我的复选框的选中状态。

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/>");


        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 2011-06-17
    • 1970-01-01
    相关资源
    最近更新 更多