简体   繁体   English

如何删除多个下拉菜单中的选项

[英]How can I remove options in multiple dropdown menus

I was wondering if someone got an idea how to remove a choice you made in multiple dropdown menus. 我想知道是否有人知道如何删除您在多个下拉菜单中所做的选择。

I have no idea if you can do it with dropdown menu's maybe I need datalist or something else. 我不知道您是否可以使用下拉菜单进行操作,也许我需要数据列表或其他内容。

But what I mean is I have for example 6 dropdown menu's like this dropdown menu's 但我的意思是我有例如6下拉菜单中的这样的下拉菜单中的

I made it so you have 1 - 6 but if I choose number 3 in the first one, how can I remove it in the 2nd menu, or make in invisible. 我做到了,所以您有1-6,但是如果我在第一个菜单中选择数字3,该如何在第二个菜单中将其删除,或者使其不可见。

I had this problem in multiple projects from me but never know how to solve it. 我曾在多个项目中遇到过这个问题,但从不知道如何解决。

Code of 1 of the menu's 菜单的1的代码

<select name="getal" form="enquete" />

  <?php
    for($i=1; $i<=5; $i++)
    {
      echo "<option value=".$i.">".$i."</option>";
    }
  ?> 
</select>

Let´s say you got 2 option select items like this: 假设您有2个选项选择项,例如:

<select name="getal" form="enquete" class="selectmenu"/>
<?php
      for($i=1; $i<=5; $i++)
    {
      echo "<option value=".$i.">".$i."</option>";
    }
?> 
</select>
<select name="getal2" form="enquete" class="selectmenu"/>
<?php
  for($i=1; $i<=5; $i++)
  {
    echo "<option value=".$i.">".$i."</option>";
  }
?> 
</select>

You can add 2 jquery selectors - they can be dynamic - I´m showing you how to do it with 2 dropdown lists: 您可以添加2个jquery选择器-它们可以是动态的-我向您展示如何使用2个下拉列表:

var $drop1 = $("#geta1");
var $drop2 = $("#geta2");

Create a function to react on change of dropdown 1 (again, you can do it on each beside the clicked one): 创建一个对下拉列表1的更改做出反应的函数(同样,您可以在单击的下拉列表旁边对每个下拉列表进行更改):

$drop1.change(function() {
    var selectedItem = $(this).val();
    if (selectedItem) {
        $drop2.find('option[value="' + selectedItem + '"]').remove();
    }
});

We are just removing the options, if you want you can re-add them when changed again. 我们只是删除这些选项,如果您想在再次更改时可以重新添加它们。 Create one array and iterate through the options, if not present, append the missing options. 创建一个数组并遍历选项(如果不存在),然后追加缺少的选项。

Is this what you want to do? 这是你想做的吗?

 $("#drop1").change(function () {
        var d1 = this.value;
        if(d1==3)
        {
        $('#drop3').hide();
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM