删除动态添加的< li>通过< img>的onClick包含在 [英] Remove dynamically added <li> via onClick of <img> contained within

查看:54
本文介绍了删除动态添加的< li>通过< img>的onClick包含在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 http://中的脚本webdeveloperplus.com/jquery/ajax-multiple-file-upload-form-using-jquery/ 我修改了onComplete,添加了一个链接以删除图像.在remove_me()函数中,我想要: 1.移除< li>对于单击的文件 2.通过ajax在服务器上调用PHP脚本,以将文件从服务器上删除,因为该文件已被上传.

I'm using the script from http://webdeveloperplus.com/jquery/ajax-multiple-file-upload-form-using-jquery/ I modified the onComplete to add a link to remove the image. In the remove_me() function, I want to: 1. remove the <li> for the file clicked 2. call a PHP script on the server via ajax to delete the file from the server due to it being uploaded already.

if(response==="success"){
  $('<li></li>').appendTo('#files').html('<img src="./uploads/'+file+'" alt="" /><br />'+file+'<br />Click to Remove<img src="cross.png" onclick="remove_me(\'./uploads/'+file+'\')" />').addClass('success');
} else{
  $('<li></li>').appendTo('#files').text(file).addClass('error');
}

在remove_me()函数中,我可以轻松获取图像名称,因为我是通过onClick传递它的,但是我不确定如何删除< li>.包含图像. 文件名将通过ajax调用传递给PHP函数.我知道该怎么做,只是删除了< li>我有麻烦了.

In the remove_me() function, I am able to get the image name easily because I'm passing it via the onClick but I am not sure how I can remove the <li> that contains the image. The filename will be passed to the PHP function via an ajax call. I know how to do that, it's just removing the <li> that I'm having trouble with.

推荐答案

我不确定您在此处显示的内容为何不起作用,因为我看不到remove_me()函数,但我将向您展示如何做这是我会做的方式.

I am not sure with what you are showing here why it is not working since i can not see the remove_me() function but I will show you how to do it the way i would do it.

您可以像这样在remove_me()函数中使用$(this):

you could use $(this) in the remove_me() function like so:

$(this).closest('li').remove();

这将从单击开始,然后转到最近的li标签并将其删除.

This would start where clicked and go to the closest li tag and remove it.

(两个达尼特人刚刚回答...我不会看起来...要学会打字更快的笑声)

(darnit two people just answered ... im not going to look ... got to learn to type faster lol)

这篇关于删除动态添加的&lt; li&gt;通过&lt; img&gt;的onClick包含在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆