我正在使用 ajax 来获取这样的 HTML 片段:
<表 id='x'>
<tr>
<td>
<a href='http://www.google.com>点我</a>
</td>
</tr>
</table>
在显示 HTML 之前,我想将目标属性添加到锚标记。
xhr = $.ajax({
dataType: 'html',
type: 'get',
url: ajaxUrl,
data: {},
success: function (data, textStatus) {
//The next line is the important bit
$(data).filter('#x').attr({target:'_blank'});
myDiv
.html(data)
.fadeIn('slow');
},
error: function (x, txt, e) {
//handle error
}
});
这不起作用。获取被操纵对象的句柄并使用它来设置 div 的 html 的正确方法是什么?