clone,appendto输入,选择,选项--javascript / jquery

时间:2012-10-11 15:46:39

标签: javascript jquery clone option appendto

我的表单中有很多选择和输入。我试图使用clone和append.to创建相同的表单,但我无法弄清楚如何克隆选定的值。输入和选择框成功打印成阵列:

[model] => 0
[powertype] => kW (input)
[dateofmy] => 0
[dateofmm] => 0
[pricetype] => NOK (input)

但是,正如您所看到的,我无法克隆选择选项值。 0无处不在。

我的代码:

$('#myForm input').each(function(item){
$($(this).clone()).appendTo($('#form2'));
});

$('#myForm select').each(function(item){
$($(this).clone()).appendTo($('#form2'));
});

$('#myForm option:selected').each(function(item){
$($(this).clone()).appendTo($('#form2'));
});

1 个答案:

答案 0 :(得分:0)

你可以在整个表格中使用.clone() ..

$("#myForm").clone().appendTo($('#form2'));

试试这个..

$('#form2').append($('#myForm').html());