简单穿梭框示例

<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>简单穿梭框示例</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
        }
        .container {
            display: flex;
            justify-content: center;
            align-items: center;
            gap: 20px;
        }
        .box {
            width: 200px;
            height: 300px;
            border: 1px solid #ccc;
            overflow-y: auto;
        }
        .box-header {
            background-color: #f5f5f5;
            padding: 8px;
            text-align: center;
            font-weight: bold;
            border-bottom: 1px solid #ddd;
        }
        .item {
            padding: 8px;
            border-bottom: 1px solid #eee;
            cursor: pointer;
        }
        .item:hover {
            background-color: #f0f0f0;
        }
        .item.selected {
            background-color: #d4e6f1;
        }
        .buttons {
            display: flex;
            flex-direction: column;
            gap: 10px;
        }
        button {
            padding: 8px 12px;
            cursor: pointer;
        }
        .footer {
            margin-top: 20px;
            text-align: center;
            color: #666;
        }
        .highlight {
            color: #e74c3c;
            font-weight: bold;
        }
    </style>
</head>
<body>
    <h1>简单穿梭框示例</h1>
    
    <div class="container">
        <div class="box">
            <div class="box-header">可选项目</div>
            <div id="left-box">
                <div class="item" data-value="1">项目1</div>
                <div class="item" data-value="2">项目2</div>
                <div class="item" data-value="3">项目3</div>
                <div class="item" data-value="4">项目4</div>
                <div class="item" data-value="5">项目5</div>
                <div class="item" data-value="6">项目6</div>
            </div>
        </div>
        
        <div class="buttons">
            <button id="to-right">&gt;</button>
            <button id="to-left">&lt;</button>
            <button id="to-right-all">&gt;&gt;</button>
            <button id="to-left-all">&lt;&lt;</button>
        </div>
        
        <div class="box">
            <div class="box-header">已选项目</div>
            <div id="right-box"></div>
        </div>
    </div>
    
    <div class="footer">
        <p>这个穿梭框示例使用了jQuery实现。</p>
    </div>

    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script>
        $(document).ready(function() {
            // 选择项目
            $('#left-box, #right-box').on('click', '.item', function() {
                $(this).toggleClass('selected');
            });
            
            // 向右移动选中的项目
            $('#to-right').click(function() {
                $('#left-box .selected').each(function() {
                    $(this).removeClass('selected').appendTo('#right-box');
                });
            });
            
            // 向左移动选中的项目
            $('#to-left').click(function() {
                $('#right-box .selected').each(function() {
                    $(this).removeClass('selected').appendTo('#left-box');
                });
            });
            
            // 全部向右移动
            $('#to-right-all').click(function() {
                $('#left-box .item').appendTo('#right-box');
            });
            
            // 全部向左移动
            $('#to-left-all').click(function() {
                $('#right-box .item').appendTo('#left-box');
            });
            
            // 双击项目快速移动
            $('#left-box').on('dblclick', '.item', function() {
                $(this).appendTo('#right-box');
            });
            
            $('#right-box').on('dblclick', '.item', function() {
                $(this).appendTo('#left-box');
            });
        });
    </script>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值