gpt4 book ai didi

javascript - jQuery 在按钮后追加

转载 作者:行者123 更新时间:2023-11-29 10:09:15 25 4
gpt4 key购买 nike

以下是我的 HTML:

<div class="row attachments-container">
<div class="row">
<div class="col-4 row-space-2 h5 invisible" id="js-first-photo-text">
Your first photo appears in search results!
</div>
</div>
<% if !@product.new_record? %>
<% @product.product_attachments.each do |attachment| %>
<div class="col-xs-6 col-md-4 form-group grayscale">
<img src="<%= attachment.attachment.small.url %>" class="upload-photo-image">
<input type="hidden" name="product_attachment[id][]" value="<%= attachment.id %>">
<button class="delete-photo-btn overlay-btn js-delete-photo-btn delete-attachment" data-photo-id="143275119">
<i class="fa fa-trash-o"></i>
</button>
<button class="cover-photo-btn cover-overlay-btn js-delete-photo-btn cover-attachment" data-photo-id="143275119">
<i class="fa fa-picture-o"></i>
</button>

</div>
<% end %>
<% end %>

<div class="col-xs-6 col-md-4 form-group">
<div class="thumbnail panel photo-item empty-photo-frame" name="empty-photo-frame">
<img src="<%= asset_url('add-image-placeholder.png') %>">
</div>
</div>

</div>

当用户决定更改 coveronClick 将触发:

$('.attachments-container').on('click', '.cover-attachment', function (event) {
$this = $(this);
var append_html = '<p class="status-notice">Saving as cover....</p>';
$this.find('.cover-attachment').append_html

var attachment_id = $(this).parent().find('input[name="product_attachment[id][]"]').val();
$.ajax({
type: "POST",
url: "/product_attachments/" + attachment_id + "/set_cover",
dataType: "json",
data: {
'attachment_id': attachment_id
},
complete: function (data) {
$this.parent().find('.status-notice').text('Saved!').fadeOut('slow');
console.log(data)
}
});
event.preventDefault();
})

问题是,status-notice 没有附加在 cover-attachment 按钮之后。

最佳答案

问题:

问题出在下面的语句

$this.find('.cover-attachment').append_html

这将返回 undefined,因为 jQuery 上没有方法/属性名称 append_html


解决方案:

Jquery append after the button

要附加 HTML,您可以使用 append() .

$this.find('.cover-attachment').append(append_html);

要完全替换/覆盖元素的 HTML,请使用 html() .

$this.find('.cover-attachment').html(append_html);

Jquery append after the button

要一个接一个地添加新元素,请使用 after()

$this.find('.cover-attachment').after(append_html);

关于javascript - jQuery 在按钮后追加,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36637729/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com