jQuery动态添加了选择

当我通过克隆向DIV添加选择动态时,我无法从新下拉列表中选择任何内容,任何想法为什么?

$(".inline-form .copyIng:first-child").clone().appendTo(".inline-form"); 

见: http : //jsfiddle.net/rxwL6/

 .trigger("refresh"); Dosen't change anything, I still can't select anything from the new dropdown. 

问题是您正在克隆已被jQM“增强”而不是原始标记的html内容。 因此,jQM不知道如何创建或刷新它。

相反,如果您提前知道标记,只需像这样插入:

 $(document).on("pageinit", function () { $("#newIng").click(function () { var tocopy = $('
'); $(".inline-form").append(tocopy); $(".copyIng").trigger("create"); }); });

这是你更新的FIDDLE

更新:来自评论。 OP有兴趣克隆下拉列表中的选项列表,因此不必每次都从数据库中检索它们。 以下是获取选项列表并将其插入到附加的新文本中的示例:

 $(document).on("pageinit", function () { $("#newIng").click(function () { var optList = $(".ingDiv select").eq(0).html(); var tocopy = $('
'); $(".inline-form").append(tocopy); $(".copyIng").trigger("create"); }); });

更新了FIDDLE