简体   繁体   English

jQuery的多个选择具有相同的文本不相同的VAL

[英]Jquery multiple select with same text not same val

Hello i have to make 3 select input with the same "option text" but value is different. 您好,我必须使用相同的“选项文本”进行3选择输入,但值不同。 i want to make disabled item on other select when is selected on one of this i have try this but not work : jsfiddle Test 我想使禁用选择其他选择上的一项时,我已经尝试过,但不起作用: jsfiddle测试

inspired by this: This jsfiddle 受此启发: 这个jsfiddle

$(".activ select").on('focus', function ()
        {
    previous = this.options[this.selectedIndex].innerHTML;
    }).change(function() {      
    var previoues_tx = previous;
    var selected = $(this).find('option:selected').text();;
    var opts = $(this)[0].options;      
    var array = $.map(opts, function(elem) {
    return (elem.text || elem.text);
    });
    //alert(previoues_tx);
    //alert(selected);
    //alert(opts);
    //alert(array);
    $('.activ select').each(function() {
        var oki = $(this).text();
        if(previoues_tx != 'Choisir---------------' )
        //alert(oki);
        {
            $('select option[text="' + previoues_tx + '"]').removeAttr('disabled'); 
        }
    $('select option[text="' + selected + '"]').attr('selected','selected').attr('disabled', true);
    $('select option[text=""]').removeAttr('disabled'); 
  });
    previous = this.options[this.selectedIndex].innerHTML;
    });

Problem is in the reference JsFiddle, similar option for all select box contain same value but in your case you kept as different. 问题出在参考JsFiddle中,所有select框的相似选项都包含相同的值,但在您的情况下,您保留为不同的值。

I modified your example see demo here 我修改了您的示例, 请参见此处的演示

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

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