[英]Jquery clone each not working as expected
我想做的是將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時,沒有任何工作..我已將上面的內容修改為:
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對象rep不會更改
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);
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.