0

我想获取所有没有空值的选择选项,然后在更改事件上克隆它们。我这可能吗?

这是我的代码:

 $(function() {
        $("#ddlSecurityQuestions1").change(function() {                     
        var index = $(this).val();
        $('#ddlSecurityQuestions2').empty();           
        $('#ddlSecurityQuestions1 option').clone().appendTo('#ddlSecurityQuestions2');            
        var otherDropDown=document.getElementById('ddlSecurityQuestions2');            
         otherDropDown.options.remove(index);             
      });
  });
4

1 回答 1

2

尝试这个:

$("#ddlSecurityQuestions1").change(function () {

    var $options = $(this).find('option').filter(function () {
        return this.value !== '';
    }).clone();

    $('#ddlSecurityQuestions2').empty();
    $options.appendTo('#ddlSecurityQuestions2');
});
于 2013-05-01T13:44:46.583 回答