【发布时间】:2023-04-07 23:55:01
【问题描述】:
例如,假设我有以下 HTML:
<div class="div-style">div text</div> <span>span text</span>
<div class="div-style">another div</div> <span>another span</span>
<div class="div-style">hello</div> <span>world</span>
现在我想做的是:(使用jQuery)
- 使用“div-style”类访问每个
<div> - 找到以下
<span> - 将当前
<span>的文本附加到跨度(实际上是在跨度文本中重复跨度文本,因此第一个跨度将显示“跨度文本跨度文本”)
【问题讨论】:
-
试试
$('.div-style').each(function(){ var t = $(this).next('span').text(); $(this).next('span').text($(this).next('span').text() + t); })
标签: javascript jquery