我想做的是将 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);
我不确定是否每个都有问题,或者其他什么问题..
请帮忙..
最佳答案
当您克隆并替换文本时,原始 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);
});
关于javascript - Jquery 克隆每个都没有按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29959769/