【问题标题】:Filter three select boxes based on previous selections根据之前的选择过滤三个选择框
【发布时间】:2013-07-10 06:22:16
【问题描述】:

我正在尝试根据之前选择的内容按顺序更改选择框。 我让它为第一个改变但不是第三个工作。 如果有人可以帮助我制作第三部作品,那就太好了。

http://jsfiddle.net/Ze5AA/21/

这是我正在使用的js:

$("#CAT_Custom_496270").change(function() { 
    if($(this).data('options') == undefined){
        $(this).data('options',$('#CAT_Custom_495029 option').clone());
    } 

    var id = $(this).val();
    var options = $(this).data('options').filter('[value*=' + id + ']');
    $('#CAT_Custom_495029').html(options);
});

$("#CAT_Custom_495029").change(function() { 
    if($(this).data('options') == undefined){
        $(this).data('options',$('#CAT_Custom_495038 option').clone());
    } 
    var id = $(this).val();
    var options = $(this).data('options').filter('[value*=' + id + ']');
    $('#CAT_Custom_495038').html(options);
});

【问题讨论】:

    标签: javascript jquery dropdownbox


    【解决方案1】:

    value attribute 过滤器的值括在引号中,因为值中有空格。

    var options = $(this).data('options').filter('[value*="' + id + '"]');
    

    Fiddle

    【讨论】:

    • @Ohgodwhy 是的。值中有一个空格。
    【解决方案2】:

    由于空格,您的值与您正在检查的内容不一致。

    你可以用引号括起来,但我只会得到你需要的值(前 3 个字符)以保持它更清晰

    您需要拆分支票,我会添加一个分隔符以方便使用。

     //html example from menu 2
        <option value="CSD: 0-45">0-45</option>
            <option value="CSD: 46-50">46-50</option> //note the colon after CSD
    
     //html from menu 3
    
    <option value="CSD: $25.40/month /20 Year Pay">$25.40/month /20 Year Pay</option>
    
    <option value="CSD: $26.05/month /20 Year Pay">$26.05/month /20 Year Pay</option>
    
    <option value="CSD: 51 $27.50/month /20 Year Pay">$27.50/month /20 Year Pay</option> //note the color again
    
    
     //the java
    
       var id = $(this).val().split(":"); //makes a 2 value array split at the colon
       var options = $(this).data('options').filter('[value*=' + id[0] + ']'); //we want the first array value (before the colon)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-07
      • 2017-12-26
      • 1970-01-01
      相关资源
      最近更新 更多