思路:
1.要获取这个图片的路径
2.如果有网址什么的要过滤掉
3.传到后台,后台删除成功
4.移除页面元素
下面是js
<!-- 删除 -->
<script type="text/javascript">
$(document).on("click","#clear",function(e){
var that = this;
var id = $(this).attr("data_id");
var rootpath='http://www.lishui.com/';
var img=$('.deleted'+id+' img').attr('src');
var clearimg = img.replace(rootpath,'');
$.ajax({
url:"{:url('common/clearimg')}",
data:{clearimgurl:clearimg},
type:'post',
async:false,
success:function(res){
if (res==2) {
$(".deleted"+id).remove();
}else{
alert('删除失败,请联系程序~')
}
}
})
});
</script>
删除代码
// 删除图片
public function clearimg()
{
$post=$this->request->post();
// dump($post);
if (!unlink(ROOT_PATH . '/public/' .$post['clearimgurl'])) {
return 1;
}else{
return 2;
}
}