如何在jQuery中的数组中用”替换”?
假设我有这个
$(document).ready(function() { var array = $.makeArray($('p')); $(array).appendTo(document.body); }); });
how
are
you
baby?
如果我想用
,预期输出是……
how are you baby?
我该怎么办? 提前致谢!
$("p").each(function () { $(this).replaceWith("" + $(this).html() + " "); });
这是一个快速而肮脏的解决方案,但如果你给我更多详细信息,那么我们可能会想出更好的解决方案。
$('p').each(function(){$(this).replaceWith(''+$(this).html()+' ')})