Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/275.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/86.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如果选择了下拉列表项,请将其删除_Php_Jquery_Kohana - Fatal编程技术网

Php 如果选择了下拉列表项,请将其删除

Php 如果选择了下拉列表项,请将其删除,php,jquery,kohana,Php,Jquery,Kohana,我在表单上有多个选择下拉列表实例,确切地说是八个。如果我在第一个“选择”下拉列表中选择了一个数字,我希望在第二个“选择”下拉列表中将所选数字隐藏到第八个 为此,我将仅显示八个select下拉列表中的两个 查看代码- 选择下拉菜单- <div class="col-xs-12 col-sm-3"> <div class="form-group"> <?php echo Form::label('test_id', 'Test', array('class' =

我在表单上有多个选择下拉列表实例,确切地说是八个。如果我在第一个“选择”下拉列表中选择了一个数字,我希望在第二个“选择”下拉列表中将所选数字隐藏到第八个

为此,我将仅显示八个select下拉列表中的两个

查看代码-

选择下拉菜单-

<div class="col-xs-12 col-sm-3">
<div class="form-group">
    <?php echo Form::label('test_id', 'Test', array('class' => 'col-xs-3 control-label')) ?>
    <div class="col-xs-9">
        <select name="test_id" id="test_id" class="form-control select2" data-placeholder="Select...">
            <option value=""></option>                                       
            <?php foreach (ORM::factory('Test')->order_by('id')->find_all() as $row) : ?>
            <option value="<?php echo $row->id ?>" 
            <?php if ($b->id == $row->id) echo 'selected="selected"' ?>>
            <?php echo $row->id ?></option>
            <?php endforeach ?>
       </select>
    </div>
</div>
这根本不起作用

任何帮助都将不胜感激


干杯

像这样的事情可能有用:

$(".select").click(function () {
    var value = $(this).val();

    // to hide every option that have the selected value
    $("option").filter(function() {    
        return $(this).val() == value;  
    }).hide();

    // to show the option currently selected in the current list
    $(this).find("option").each(function () {
        if ($(this).val() == value)
        {
            $(this).show();
        }
    });
});

希望有此帮助。

这不适用于select2和隐藏选项。您可以通过禁用这些选项和一些CSS来隐藏它们来解决这个问题。见下文:

JS

CSS


这里的工作示例:

为工作伙伴弗拉德干杯

为了使jQuery更加优化,我们完成了这项工作

$(document).ready(function () {
  var $selects = $('select');
  $selects.select2();
  $('select').change(function () {
     $('option:hidden', $selects).each(function () {
        var self = this,
                toShow = true;
        $selects.not($(this).parent()).each(function () {
           if (self.value == this.value) toShow = false;
        })
        if (toShow) {
           $(this).removeAttr('disabled');
        }
     });
     if (this.value != "") {
        $selects.not(this).children('option[value=' + this.value + ']').attr('disabled', 'disabled');
     }
  });
})
谢谢你的帮助:)

试试这个
您可以像这样简单地从drop doen中删除所选项目。下拉id为“选择id”,所选选项id必须为“选项id”。如果不等于两者,则“已选择”选项将为“删除”

是否可以显示所选择内容的呈现html而不是php。另外,您发布的两个php代码片段看起来完全相同-如果正确,则ID应该是唯一的。这是$(document).ready()中的jQuery代码?是的,它是$(document).ready()VladIt似乎正在工作:。我还尝试添加重复的ID,以查看是否会破坏它,并且它可以工作。请稍候,您是否使用select2进行选择?不客气。如果答案解决了你的问题,请接受它。读者在给出答案的同时进行一些解释,这样他们就可以理解它的作用。
$(".select").click(function () {
    var value = $(this).val();

    // to hide every option that have the selected value
    $("option").filter(function() {    
        return $(this).val() == value;  
    }).hide();

    // to show the option currently selected in the current list
    $(this).find("option").each(function () {
        if ($(this).val() == value)
        {
            $(this).show();
        }
    });
});
$(document).ready(function () {
    var $selects = $('select');
    $selects.select2();
    $('select').change(function () {
        $('option:hidden', $selects).each(function () {
            var self = this,
                toShow = true;
            $selects.not($(this).parent()).each(function () {
                if (self.value == this.value) toShow = false;
            })
            if (toShow) {
                $(this).removeAttr('disabled');
                $(this).parent().select2();
            }
        });
        if (this.value != "") {
            $selects.not(this).children('option[value=' + this.value + ']').attr('disabled', 'disabled');
            $selects.select2();
        }
    });
})
.select2-results .select2-disabled {
    display:none;
}
$(document).ready(function () {
  var $selects = $('select');
  $selects.select2();
  $('select').change(function () {
     $('option:hidden', $selects).each(function () {
        var self = this,
                toShow = true;
        $selects.not($(this).parent()).each(function () {
           if (self.value == this.value) toShow = false;
        })
        if (toShow) {
           $(this).removeAttr('disabled');
        }
     });
     if (this.value != "") {
        $selects.not(this).children('option[value=' + this.value + ']').attr('disabled', 'disabled');
     }
  });
})
$("#Select_id").blur(function () {
        var value = $(this).val();
        alert($("#Select_id").val() == value);
        // to hide every option that have the selected value
        if ($("#Select_id").val() == value) {
            $("#Option_id"+value).hide();
        }
    });