我有以下html构造函数,内容是动态添加的
<div class="media text-muted pt-3">
<img data-src="holder.js/32x32?theme=thumb&bg=d32f2f&fg=d32f2f&size=1" alt="todo" class="mr-2 rounded">
<div class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
<div class="d-flex justify-content-between align-items-center w-100">
<strong class="text-gray-dark">{{ $ticketValue->title }}</strong>
</div>
<br>
<div class="d-flex justify-content-between align-items-center w-100">
<span class="d-block">
<strong>Erstellt von {{ $ticketValue->description }}</strong>
</span>
<button type="button" class="closing-ticket" data-ticket-id="{{ $ticketValue->id }}">
<i class="fas fa-check"></i>
</button>
</div>
</div>
</div>
如果用户单击按钮,我想更改当前父图像标签的data-src。 到目前为止,我已经做到了:
this.closingTicket.click((e) => {
let _this = $(e.currentTarget);
axios.post('ticket/close/' + this.elements.closingTicket.attr('data-ticket-id'))
.then((response) => {
_this.hide(); // hides buttons
// trying to find the image and change its data-src
_this.parent().parent().parent().find('img').data('src', 'holder.js/32x32?theme=thumb&bg=64dd17&fg=64dd17&size=1');
})
.catch((error) => {
// error
})
});