我该如何转动它:
<a class="link">
<p class="paragraph">This is some text</p>
<p class="paragraph">This is some more text</p>
<p class="paragraph">And some more</p>
</a>
进入此:
<a class="link">
This is some text This is some more text And some more
</a>
使用 jQuery。我尝试使用追加和合并,但我就是不明白。
最佳答案
自 text
方法返回元素及其后代的文本内容,您可以使用它:
var link = $("a.link");
link.text(link.text());
来自文档:
Get the combined text contents of each element in the set of matched elements, including their descendants.
这是一个working example .
更新(见评论)
如果需要应用于多个 .link
元素,您可以使用 each
:
$("a.link").each(function() {
$(this).text($(this).text());
});
关于javascript - 如何使用 jquery/Javascript 将段落合并到父链接中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10019538/