复制/克隆下拉列表,并在jquery中选择选项 [英] copy/Clone dropdown list with selected option in jquery

查看:194
本文介绍了复制/克隆下拉列表,并在jquery中选择选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用选定的选项克隆下拉列表(组合框)?

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

jquery .clone方法在 firefox 中不能用于选定的选项。

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

我有一个div有不同的控件。我必须将整个div复制到一个这样的变量。

I have a div having different controls. I have to copy entire div to a variable something like this

var $orginalDiv = $('#myDiv');
var $clonedDiv = $orginalDiv.clone();

$clonedDiv.find('select').each(function() {


....Something do here for assigning selected options from original div ..

            });

让我知道如何完成它,并且必须在FireFox中使用。

Let me know how can we get it done and it must be worked in FireFox.

推荐答案

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() );

});

尝试一下这里在jsfiddle

Try it here at jsfiddle

这篇关于复制/克隆下拉列表,并在jquery中选择选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆