尝试使用以下函数将 div 附加到另一个customizefields
,但我没有成功。控制台不返回任何错误,所以我不知道从这里去哪里?
javascript
function customizefields(objNames) {
$('td div').each(function(){
name = $(this).text();
if (name.indexOf(" ") != -1) {
name = name.substring(0, name.indexOf(" "));
}
if (objNames[name]) {
$('<div/>', {
id: 'bio',
text: objNames[name].bio
}).appendTo(this);
}
});
}
var namesToChange = {
'Ben':{'class':'pn_cool','bio':'some text for ben'},
'Andrew':{'class':'pn_bad','bio':'some text for andrew'}
};
setInterval(function(){customizefields(namesToChange)}, 1000);
html
<tr>
<td class="stxt2">
<img src="#" class="pic">
<div class="dtxt2" title="07/10/12 09:40 PM">40 mins ago</div>
<b class="nme pn_usr">Andrew</b>: Ut lacus sapien, pretium ut dictum eget, tempus ac nisi.
</td>
</tr>
<tr>
<td class="stxt">
<img src="#" class="pic">
<div class="dtxt" title="07/10/12 09:30 PM">30 mins ago</div>
<b class="nme pn_usr">Ben</b>: Cras vitae cursus lectus.
</td>
</tr>
<tr>
我试图达到的结果
<tr>
<td class="stxt">
<img src="#" class="pic">
<div id="bio">TEXT FROM OBJECT WILL GO HERE</div>
<div class="dtxt" title="07/10/12 09:30 PM">30 mins ago</div>
<b class="nme pn_usr">Ben</b>: Cras vitae cursus lectus.
</td>
</tr>
<tr>