我要做的是将ddl转换为无序列表并删除第一个子元素。当我只有1 ddl转换时,这很有效。
这些是我的代码:
var rep = jQuery(".input-box select")
.clone()
.find("option:first")
.remove().end()
.wrap("<div></div>")
.parent().html()
.replace(/select/g,"ul")
.replace(/option/g,"li");
jQuery(".price-info").append(rep);
当我有多个ddl \ s进行克隆时,没有任何工作......我已将上述内容修改为此内容:
var rep = jQuery(".input-box select");
rep.each(function(){
jQuery(this)
.clone()
.find("option:first")
.remove().end()
.wrap("<div></div>")
.parent().html()
.replace(/select/g,"ul")
.replace(/option/g,"li");
});
jQuery(".price-info").append(rep);
我不确定每个问题是否存在问题或其他问题。
请帮助..
答案 0 :(得分:1)
当您克隆并替换文本时,原始jQuery对象代表不会更改
var rep = jQuery(".input-box select");
rep.each(function () {
var html = jQuery(this)
.clone()
.find("option:first")
.remove().end()
.wrap("<div></div>")
.parent().html()
.replace(/select/g, "ul")
.replace(/option/g, "li");
jQuery(".price-info").append(html);
});