如何删除多个下拉菜单中的选项 [英] How can I remove options in multiple dropdown menus

查看:85
本文介绍了如何删除多个下拉菜单中的选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有人想出如何删除您在多个下拉菜单中所做的选择。

I was wondering if someone got an idea how to remove a choice you made in multiple dropdown menus.

我不知道你是否可以通过下拉菜单来做,也许我需要datalist或其他东西。

I have no idea if you can do it with dropdown menu's maybe I need datalist or something else.

但是我的意思是我有6个下拉菜单,像这样
下拉菜单的< a>

But what I mean is I have for example 6 dropdown menu's like this dropdown menu's

我做了所以你有1 - 6,但如果我在第一个选择3号,我如何删除它在第二个菜单,或使无形。

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.

我在我的多个项目中遇到了这个问题,但从来不知道如何解决它。

I had this problem in multiple projects from me but never know how to solve it.

代码1菜单的

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

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


推荐答案

让我们说你有2个选项选择项这个:

Let´s say you got 2 option select items like this:

<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>

您可以添加2个jquery选择器 - 它们可以是动态的 - 我向您展示如何做有2个下拉列表:

You can add 2 jquery selectors - they can be dynamic - I´m showing you how to do it with 2 dropdown lists:

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

创建一个功能来对下拉列表1的更改做出反应(再次,您可以在点击一个):

Create a function to react on change of dropdown 1 (again, you can do it on each beside the clicked one):

$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.

这是你想要做的吗?

这篇关于如何删除多个下拉菜单中的选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆