码迷,mamicode.com
首页 > 其他好文 > 详细

两个select转移

时间:2015-11-05 00:43:13      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:

<table>
            <tr>
                <td>
                    <select multiple="multiple" id="leftSelect">
                        <optgroup label="可选择">
                            <option value="1">1111</option>
                            <option value="2">2222</option>
                            <option value="3">3333</option>
                            <option value="4">4444</option>
                        </optgroup>
                    </select>
                </td>
                <td>
                    <span href="javascript:;" class="moveBtn" from="#leftSelect" to="#rightSelect">右移</span>
                    <br />
                    <br />
                    <span href="javascript:;" class="moveBtn" from="#rightSelect" to="#leftSelect">左移</span>
                </td>
                <td>
                    <select multiple="multiple" id="rightSelect">
                        <optgroup label="可用"></optgroup>
                    </select>
                </td>
            </tr>
        </table>
 <script>
        $(function () {
            $(".moveBtn").click(function () {
                var from = $($(this).attr("from"));
                var to = $($(this).attr("to"));
                var selected = from.find(":selected").attr("selected", false).toArray();
                var option = to.find("option").toArray();
                var arr = selected.concat(option).sort(function (a, b) { return a.value - b.value });
                to.find("optgroup").append(arr);
            });
        });
    </script>

 

两个select转移

标签:

原文地址:http://www.cnblogs.com/talentzemin/p/4937888.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!