0

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

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);
});
4

2 回答 2

1

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

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

小提琴

于 2013-07-11T20:18:06.153 回答
0

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

你可以用引号括起来,虽然我只会得到你需要的值(前 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)
于 2013-07-11T20:43:10.373 回答