它提交值
// Slider Image
echo '<input style="width:100%" type="hidden" id="all_img" name="all_img" value="' . $all_img .'" />';
删除选项删除
$s_img = explode(',', $single_img);
for ( $i = 0; $i < count( $s_img ); $i++ ) {
echo '<li id="delete_img"><div class="delete"><div alt="f158" class="dashicons dashicons-no" style="display: inline-block;"></div></div>';
echo '<img src="'.wp_get_attachment_image_url( $s_img[$i], 'full', false ).'" alt="slider image"/><li>';
}
删除图像删除图像javascript文档正文,然后一键删除ID
$(document.body).on('click', '.sarea .delete', function() {
$('#single_img').remove();
});
答案 0 :(得分:0)
在您的示例中,您为id="delete_img"
循环中的所有图像使用了相同的for
:
for ( $i = 0; $i < count( $s_img ); $i++ ) {
echo '<li id="delete_img"><div class="delete"><div alt="f158" class="dashicons dashicons-no" style="display: inline-block;"></div></div>';
echo '<img src="'.wp_get_attachment_image_url( $s_img[$i], 'full', false ).'" alt="slider image"/><li>';
}
// delete image
$('#single_img').remove();
由于您使用的是jQuery,因此您可以尝试执行以下操作:
// When you click on your delete icon...
$('.delete').on('click', function() {
// It will select the parent element <li> and remove it.
$(this).parent().remove();
});
例如:
$('.delete').on('click', function() {
$(this).parent().remove();
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<ul>
<li>
<button type="button" class="delete">X</button>
<span>Icon</span>
<span>Image 1</span>
</li>
<li>
<button type="button" class="delete">X</button>
<span>Icon</span>
<span>Image 2</span>
</li>
<li>
<button type="button" class="delete">X</button>
<span>Icon</span>
<span>Image 3</span>
</li>
</ul>