我无法使用最接近的img标签追加图像src。无法使用最接近的img标签追加图像src
当自动完成选项选择我要填充的图像该行
HTML:
<td>
<div>
<img class="participantphoto" src="images/author2.jpg" width="50" />
<input placeholder="Type a letter to search students" class="form-control searchStudent formbottom" name="student[0][name]" type="text" autocomplete="off">
</div>
</td>
JS:
$(document).on("focus keyup", "input.searchStudent", function (event) {
$(this).autocomplete({
source: 'gdcontroller.php?action=search',
select: function (event, ui) {
console.log(ui);
event.preventDefault();
this.value = ui.item.label;
// line below fails
$(this).parent().closest(".participantphoto").attr("src",ui.item.profile_pic);
},
focus: function (event, ui) {
event.preventDefault();
this.value = ui.item.label;
}
});
});
$(本).parent()最接近(”。 participantphoto“).attr(”src“,ui.item.profile_pic);不管用。 –
这是非常值得**的时间来阅读您尝试使用的方法(通常只需要一个小时,两个上面)的jQuery API文档。 ['closest'](http://api.query.com/closest)不会做你认为它的事情。 –