Jquery 依赖dropdownlist按在第一个dropdownlist中选择的递增顺序正常工作,但按递减顺序失败

Jquery 依赖dropdownlist按在第一个dropdownlist中选择的递增顺序正常工作,但按递减顺序失败,jquery,drop-down-menu,Jquery,Drop Down Menu,我不熟悉Jquery。我已经编写了一个相关的dropdownlist,其中我从第一个dropdownlist中选择了一个值,所有大于第一个dropdownlist的值都会显示在第二个dropdownlist中。 当我在第一个下拉列表中选择一个值时,将调用以下函数: <script> function cost_change(price) { var value = price; console.log("value",value); var

我不熟悉Jquery。我已经编写了一个相关的dropdownlist,其中我从第一个dropdownlist中选择了一个值,所有大于第一个dropdownlist的值都会显示在第二个dropdownlist中。 当我在第一个下拉列表中选择一个值时,将调用以下函数:

<script>    
function cost_change(price) {
    var value = price;
    console.log("value",value);      
    var toKeep = jQuery('#SearchForm_max_cost_select option').filter( function( ) {
        return parseInt(this.value) > parseInt( value);       
 } );        
   console.log("to keep",toKeep);
   jQuery('#SearchForm_max_cost_select').html(toKeep);
}
</script>  
现在,函数工作正常,但问题是, 我第一次从第一个dropdownlist中选择了3,然后在第二个dropdownlist中显示了值[4,5,6]。 之后,我从第一个dropdownlist中选择2,然后在第二个dropdownlist中显示值[4,5,6],而不是[3,4,5,6]。 当我在第一个下拉列表中按递增顺序选择数字时,显示的值可以正常工作。但当我将first dropdownlist中的值减小到之前选择的值以下时,没有任何变化

是缓存有问题还是必须修改上述函数。

编辑: 传递给函数cost_change的可变价格是在第一个dropdownlist中选择的值,可以正常工作

HTML:


您的主要问题是,当您第一次过滤时,第二个下拉列表中的选项会被重新绘制,因此当您再次尝试进行过滤时,将没有更多选项与条件匹配

在对第二个下拉列表进行筛选时,需要重新绑定它

$('#SearchForm_max_cost_select').html($('#SearchForm_min_cost_select').html())
看看这里,它会对你有用的

function cost_change(price) {
    var value = price;
    console.log("value",value);     
    $('#SearchForm_max_cost_select').html($('#SearchForm_min_cost_select').html());
    var toKeep = jQuery('#SearchForm_max_cost_select option').filter( function( ) {
        return parseInt(this.value) > parseInt( value);       
 } );        
   console.log("to keep",toKeep);
   jQuery('#SearchForm_max_cost_select').html(toKeep);
}

这是

你能在这里显示你的html吗?或者做一把小提琴?@nrsharma我把它贴在了你叫cost_changeprice的地方?@nrsharma我在用一个Yii小部件$此->小部件'ext.combobox.EJuiComboBox',数组'model'=>$model',属性'=>min\u cost',数据'=>Yii::app->参数['cost\u min\u resales','options'=>array'onSelect'=>cost\u changeitem.value;','allowText'=>false,,'htmlOptions'=>array'placeholder'=>'Min Cost','style'=>'width:70px'@nrsharma请建议我该怎么做
function cost_change(price) {
    var value = price;
    console.log("value",value);     
    $('#SearchForm_max_cost_select').html($('#SearchForm_min_cost_select').html());
    var toKeep = jQuery('#SearchForm_max_cost_select option').filter( function( ) {
        return parseInt(this.value) > parseInt( value);       
 } );        
   console.log("to keep",toKeep);
   jQuery('#SearchForm_max_cost_select').html(toKeep);
}