遍历JQuery对象并替换文本
假设我有下面的html div,我想复制它的子对象,在这个过程中更改每个跨度的值遍历JQuery对象并替换文本,jquery,Jquery,假设我有下面的html div,我想复制它的子对象,在这个过程中更改每个跨度的值 <div><span class="foo">[Name]</span> <span class="bar">[Name]</span></div> 然后像中一样克隆 var clone = $div.children().clone(); 然后如何遍历克隆并更改每个跨度的值 clone.find("span").text("new val
<div><span class="foo">[Name]</span> <span class="bar">[Name]</span></div>
然后像中一样克隆
var clone = $div.children().clone();
然后如何遍历克隆并更改每个跨度的值
clone.find("span").text("new value");
或
或
或者其他很多方式
clone.find('span').each(function() {
$(this).text('Hahahha');
});
或
或
或者很多其他的方式。在我的脑海里
clone.find('span').each(function() {
$(this).text('Hahahha');
});
var clone = $div.children().clone().each(function(){
var textVale = $(this).text();
//process the text;
$(this).text(textValue);
}
);
这没有经过任何方式的测试,但我希望你能理解我的想法。从我的头脑中
var clone = $div.children().clone().each(function(){
var textVale = $(this).text();
//process the text;
$(this).text(textValue);
}
);
这没有经过任何方式的测试,但我希望你能明白这一点。我认为你可以做到:
clone = $div.clone();
clone.children.each(function(i) {
this.text("replacement text");
});
我现在不能测试它,但手册页是。我想你可以做:
clone = $div.clone();
clone.children.each(function(i) {
this.text("replacement text");
});
我现在不能测试它,但是手册页是