美文网首页
jQuery实现简单穿梭框(不带中间按钮)

jQuery实现简单穿梭框(不带中间按钮)

作者: 吕保鑫 | 来源:发表于2020-06-01 13:32 被阅读0次
    transfer.png
    <div class="shuttleDiv">
      <div class="shuttleLift">
        <div class="shuttleTit1">客服分组</div>
        <ul class="shuttleList">
        </ul>
      </div>
      <div class="shuttleRight">
        <div class="shuttleTit">已选分组:0</div>
        <ul class="addShuttle">
        </ul>
      </div>
    </div>
    
    .shuttleDiv{
        width: 478px;
        height: 250px;
        background: rgba(255,255,255,1);
        border: 1px solid rgba(227,228,233,1);
        display:flex;
        margin:0 auto !important;
    }
    
    .shuttleLift {
        width: 287px;
        border-right: 1px solid rgba(227,228,233,1);
        margin: 0 !important;
    }
    .shuttleRight {
        width: 189px;
        margin: 0 !important;
    }
    .shuttleTit, .shuttleTit1 {
        height: 30px;
        line-height: 30px;
        border-bottom: 1px solid rgba(227,228,233,1);
        font-size: 14px;
        color: rgba(102,102,102,1);
        padding-left: 10px;
        margin: 0 !important;
    }
    .shuttleList, .addShuttle {
        margin: 0 !important;
        padding: 0px;
        list-style-type: none;
        overflow-x: scroll;
        max-height: 218px;
    }
        .shuttleList li {
            height: 30px;
            line-height: 30px;
            padding: 0px 10px;
            display: flex;
            align-content: center;
            align-items: center;
        }
            .shuttleList li input {
                margin: 0 !important;
            }
            .shuttleList li label {
                margin: 0 !important;
            }
            .shuttleList li:hover, .addShuttle li:hover {
                background: rgba(220,245,255,1);
            }
        .addShuttle li {
            height: 30px;
            line-height: 30px;
            display: flex;
            align-content: center;
            justify-content: space-between;
            padding: 0px 10px;
           
        }
            .addShuttle li div {
                margin: 0 !important;
            }
            .shuttleDel {
                cursor: pointer;
                color: #009BDB;
            }
    .forbg {
        background: rgba(220,245,255,1);
    }
    
    
    var shuttleListli
            for (var i = 0; i < 15; i++) {
                shuttleListli = '<li><input type="checkbox" name="客服分组' + i + '" value="" id="one ' + i + '" onclick="onClickHander(this)" class="forinput" /> <label for="one ' + i + '" class="fortext">客服分组' + i + '</label></li>'
                $(".shuttleList").append(shuttleListli)
            }
            function onClickHander(obj) {
                if (obj.checked) {
                    $(".addShuttle").append('<li><div class="shuttletxt">' + obj.name + '</div><div class="shuttleDel">移除</div></li>')
                    $(obj).parent().addClass("forbg")
                } else {
                    $('.addShuttle li').each(function (i,v) {
                    var text = $(this).find($(".shuttletxt")).text()
                        if (obj.name == text) {
                            $(this).remove()
                        }
                    });
                    $(obj).parent().removeClass("forbg")
                }
                $(".shuttleTit").text("已选分组:" + $(".addShuttle li").length)
            }
            $('body').on('click', '.shuttleDel', function () {
                $(this).parent().remove()
                var fortxt = $(this).prev().text()
                $('.shuttleList li').each(function () {
                    var that = $(this)
                    var fortext = that.find($(".fortext")).text()
                    if (fortxt == fortext) {
                        that.find($(".forinput")).removeAttr("checked")
                        that.removeClass("forbg")
                    }
                });
                $(".shuttleTit").text("已选分组:" + $(".addShuttle li").length)
            });
    

    相关文章

      网友评论

          本文标题:jQuery实现简单穿梭框(不带中间按钮)

          本文链接:https://www.haomeiwen.com/subject/dvgjzhtx.html