2

这是类名为“ assistance_wrap ”的示例 div。

<div class="assistance_wrap">
<div class="top"></div>
<div class="header highlight">Types of assistance offered at this event:</div>
<div class="nearby_header highlight">This event is currently full, but there are other ways you can</div>
</div>

我已经克隆了这个 div,每个克隆的版本都有一个唯一的 ID。

<div id="assistance_wrap_315" class="assistance_wrap">
<div class="top"></div>
<div class="header highlight">Types of assistance offered at this event:</div>
<div class="nearby_header highlight">This event is currently full, but there are other ways you can</div>

<div id="assistance_wrap_316" class="assistance_wrap">
<div class="top"></div>
<div class="header highlight">Types of assistance offered at this event:</div>
<div class="nearby_header highlight">This event is currently full, but there are other ways you can</div>

在我的 JS 中,我将名称new_info分配给具有类“assistance_wrap”的示例 div 的副本,并为其分配唯一的 Id 并显示在我的页面上。现在我想更改类near_header 中的文本突出显示谁的父 div id 是 assistance_wrap_316我应该怎么做?

这是我尝试过的。日志的输出基本上是 id 为assistant_wrap_316的 div 的整个文本。

console.log(new_info.find('#assistance_wrap_'+ event_data.eventId , '.nearby_header highlight').text());

假设 event_data.eventId 的值为 316

4

1 回答 1

2

你应该删除","

console.log($('#assistance_wrap_'+ event_data.eventId + ' .nearby_header').text());

或使用find()方法:

console.log($('#assistance_wrap_'+ event_data.eventId).find('.nearby_header').text());
于 2012-07-17T22:44:43.470 回答