Jquery 从多选中删除/追加项目到多选

发布于 2024-09-28 02:53:32 字数 1246 浏览 8 评论 0原文

我有3个多项选择。在第一个 Select1(左)中,我加载了一组模块。在第三个 Select3(右)中,我加载另一组模块。用户可以从左侧进行选择,然后单击“添加”以从左侧删除该项目并将其附加到 Select2(中间)。用户可以对右侧执行相同的操作,选择的项目会点击不同的添加,其中选择的内容将附加到中间并从右侧删除。

这一切都很好。

我想让用户从中间多选中删除。我只想删除一次。如果用户选择正式包含在左侧和右侧多选中的项目,我希望它们从中间删除并根据原始来源附加到左侧和右侧。 我有一个变量设置来确定中间选择的模块最初来自哪里。

我在从中间返回到左/右多项选择的实际附加/删除 ITEM 时遇到问题。我用谷歌搜索并尝试了各种方法,但花费的时间太长了。

以下脚本仅显示与左侧和中间选择的交互。我将使用任何解决方案作为中右关系的模型。

任何帮助将不胜感激

<script src="js/jquery.js" type="text/javascript"></script>  
<script type="text/javascript">  
 $().ready(function() {  
  $('#add_mod').click(function() {  
   return !$('#select1_mod   option:selected').remove().appendTo('#select2_mod');
  });  
  $('#remove_mod').click(function() {  
   var x = "<%= str(modules) %>";  
   $("#select2_mod option:selected").each(function (i,selected) {  
    var thismod = $(this).text();  
    if (x.match(thismod))   
     // HELP Here I want to append this item (text and value) to Select1  
     // HELP Plus, remove this item from Select 2
                           //else after I get a solution for Left/Middle   
   });  
                    // HELP And then return Select1, Select2, Select3  
  });  
 });  
</script>  

I have 3 multiple selects. In the first Select1(left) I load a group of modules. In the 3rd Select3(right) I load another group of modules. The user can select from the Left and hit an add to remove the item from the Left and append it to the Select2(Middle). The user can do the same with the Right, select items hit a different add where the selections will be appended to the middle and removed from the Right.

This all works fine.

I want to enable the user to remove from the Middle multi-select. I only want one occurence of the remove . If the user selects items that were formally contained in both the Left and Right multi-select I want them to be removed from the Middle and appended to the Left and Right according from where the orignially came from.
I have a variable setup to determine where the module selected in the middle originally came from.

Im having problems with the actual append/removal of the ITEM from the middle back to the Left / Right multiple selects. Ive googled and tried various things but its taking too long.

The following script shows only the interaction with the Left and Middle selects. I will use any solutions as a model for the Middle, Right relationship.

Any help would be greatly appreciated

<script src="js/jquery.js" type="text/javascript"></script>  
<script type="text/javascript">  
 $().ready(function() {  
  $('#add_mod').click(function() {  
   return !$('#select1_mod   option:selected').remove().appendTo('#select2_mod');
  });  
  $('#remove_mod').click(function() {  
   var x = "<%= str(modules) %>";  
   $("#select2_mod option:selected").each(function (i,selected) {  
    var thismod = $(this).text();  
    if (x.match(thismod))   
     // HELP Here I want to append this item (text and value) to Select1  
     // HELP Plus, remove this item from Select 2
                           //else after I get a solution for Left/Middle   
   });  
                    // HELP And then return Select1, Select2, Select3  
  });  
 });  
</script>  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉城 2024-10-05 02:53:32

最后的答案和往常一样非常简单。

<script type="text/javascript">  
        $().ready(function() {  
        $('#add_mod').click(function() {  
            return !$('#select1_mod   option:selected').remove().appendTo('#select2_mod');  
        });  
        $('#remove_mod').click(function() {  
            var x = "<%= str(modules) %>";  
            var thisind = 0;  
            $("#select2_mod option:selected").each(function (index) {  
                var thismod = $(this).text();  
                var thisval = $(this).val();  
                if (x.match(thismod)) {  
                    $(this).remove().appendTo('#select1_mod');}  
                else {  
                    $(this).remove().appendTo('#select1_ms');}                      
            });  
        });  
        $('#add_ms').click(function() {  
            return !$('#select1_ms   option:selected').remove().appendTo('#select2_mod');  
        });  
        $('#remove_ms').click(function() {  
            return !$('#select2_ms   option:selected').remove().appendTo('#select1_ms');  
        });  

    });  
</script>

the answer as usual was really simple in the end.

<script type="text/javascript">  
        $().ready(function() {  
        $('#add_mod').click(function() {  
            return !$('#select1_mod   option:selected').remove().appendTo('#select2_mod');  
        });  
        $('#remove_mod').click(function() {  
            var x = "<%= str(modules) %>";  
            var thisind = 0;  
            $("#select2_mod option:selected").each(function (index) {  
                var thismod = $(this).text();  
                var thisval = $(this).val();  
                if (x.match(thismod)) {  
                    $(this).remove().appendTo('#select1_mod');}  
                else {  
                    $(this).remove().appendTo('#select1_ms');}                      
            });  
        });  
        $('#add_ms').click(function() {  
            return !$('#select1_ms   option:selected').remove().appendTo('#select2_mod');  
        });  
        $('#remove_ms').click(function() {  
            return !$('#select2_ms   option:selected').remove().appendTo('#select1_ms');  
        });  

    });  
</script>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文