copy/Clone dropdown list with selected option in jquery

后端 未结 3 1334
半阙折子戏
半阙折子戏 2020-12-31 07:33

How can I clone dropdown list(combobox) with selected option?

jquery .clone method is not working in firefox for selected option.

I have a

相关标签:
3条回答
  • 2020-12-31 08:02
    var $orginalDiv = $('#myDiv');
    var $clonedDiv = $orginalDiv.clone();
    
    //get original selects into a jq object
    var $originalSelects = $orginalDiv.find('select');
    
    $clonedDiv.find('select').each(function(index, item) {
    
         //set new select to value of old select
         $(item).val( $originalSelects.eq(index).val() );
    
    });
    

    Try it here at jsfiddle

    0 讨论(0)
  • 2020-12-31 08:08

    Can you implement a button to clone the drop downs?

    0 讨论(0)
  • 2020-12-31 08:11

    Hi you have a customedropdown with some image mask then simple clone will not display a selected value, for that you have to first assign a selected value of one dropdown to second drop down, and then call a change event implicitly like following. $('select[id*=cstate]').val($("select[id*=state]").val()); $("#cstate").change();

    0 讨论(0)
提交回复
热议问题