easyui combtree 单选的时候实现 再次点击取消选中

easyui combtree 单选的时候实现 再次点击取消选中

原理

就是在 select 的时候判断当前节点是否选中, 选中了的话就通过改变 节点 的class 属性来取消选中, 并且清空combotree 的值。同时 return false ,让本次 select 不能实现选中

代码如下

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>ComboTree Actions - jQuery EasyUI Demo</title>
    <link rel="stylesheet" type="text/css" href="../themes/default/easyui.css">
    <script src="../jquery.min.js"></script>
    <script src="../jquery.easyui.min.js"></script>
</head>

<body>
    <h2>ComboTree Actions</h2>
    <p>Click the buttons below to perform actions</p>
    <div style="margin:20px 0">
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="getValue()">GetValue</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="setValue()">SetValue</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="disable()">Disable</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="enable()">Enable</a>
    </div>
    <div class="easyui-panel" style="width:100%;max-width:400px;padding:30px 60px;">
        <div style="margin-bottom:20px">
            <input id="cc">
        </div>
    </div>
    <script type="text/javascript">
        function getValue() {
            var val = $('#cc').combotree('getValue');
            alert(val);
        }

        function setValue() {
            $('#cc').combotree('setValue', '122');
        }

        function disable() {
            $('#cc').combotree('disable');
        }

        function enable() {
            $('#cc').combotree('enable');
        }
        $(function () {
            $('#cc').combotree({
                onBeforeSelect: function (node) {
                    // debugger;
                    var isSelected = $(node.target).hasClass('tree-node-selected');

                    if (isSelected) {
                        $(node.target).removeClass('tree-node-selected'); // 去除树上 节点的 class
                        $('#cc').combotree('clear'); // 同时需要 combobox 的值
                        return false; // 本次点击不选中
                    }
                },
                // unselect: fu
                data: [{
                    id: 1,
                    text: 'Languages',
                    children: [{
                        id: 11,
                        state: 'close',
                        text: 'Java'
                    }, {
                        id: 12,
                        text: 'C++'
                    }]
                }]
            });
        });
    </script>

</body>
</html>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值