选中后如何从选择框中删除值

时间:2014-01-20 11:18:44

标签: jquery select csv jquery-plugins tags

我要做的是上传CSV文件,然后计算文件的列,然后根据内容排列。

例如:CSV文件中有3列,用户现在可以确定列的内容,以便将其正确上传到数据库。

如何在用户选择将从选择框中禁用的值后,使用选择选项填写输入框。

enter image description here

选择框将包含特定值。

enter image description here

选择后,现在将禁用或删除该值,直到从上一个选择框中取消选择。

enter image description here

类似于 Jquery Tag's Multi Selector http://harvesthq.github.io/chosen/#multiple-select

但它将分发到从CSV文件创建的每一行。

1 个答案:

答案 0 :(得分:1)

尝试一下:http://jsfiddle.net/rM88C/2/

它应该允许您添加不确定数量的“Jquery Chosen”下拉列表,并且在具有相同类名的所有下拉列表中“禁用”任何选定值。我提供了一个多选版本,但为了您的目的将其转换为单个选择版本应该是微不足道的。

下面提供的Javascript代码,但请先查看Fiddle

// get selects for later use
var selects = $('.myChosen');

// whenever the selection changes, either disable or enable the 
// option in the other selects
selects.chosen().change(function() {
    var selected = [];

    // add all selected options to the array
    selects.find("option").each(function() {
        if (this.selected) {
            selected[this.value] = this;
        }
    })

    // disable or enable options
    .each(function() {

        // if the current option is already selected in another select disable it.
        // otherwise, enable it.
        this.disabled = selected[this.value] && selected[this.value] !== this;
    });

    // trigger the change event in the other "chosen" selects
    selects.trigger("chosen:updated");
});
相关问题