jQuery删除项目按钮单击(jQuery Remove Item On Button Click)

编程入门 行业动态 更新时间:2024-10-21 15:51:37
jQuery删除项目按钮单击(jQuery Remove Item On Button Click)

我只是想在点击按钮时删除这些项目,我遇到了麻烦。 我也看过其他类似的帖子,但我不熟悉jQuery,所以我仍然遇到麻烦。

我希望能够在按钮点击时删除单个项目。

谢谢! :)

jQuery的:

$("#cart_remove").click(function() { $("#cart_remove").parent("#cart_g_id").html(); });

HTML:

<tr id="cart_g_id"> <td> <a id="cart_remove">Remove</a> </td> </tr> // I have multiple items here

I simply want to remove these items on button click, and I'm having trouble. I've had a look at other similar posts too, but I'm not familiar with jQuery so I'm still having trouble.

I want to be able to delete individual items on button click.

Thanks! :)

jQuery:

$("#cart_remove").click(function() { $("#cart_remove").parent("#cart_g_id").html(); });

HTML:

<tr id="cart_g_id"> <td> <a id="cart_remove">Remove</a> </td> </tr> // I have multiple items here

最满意答案

您需要在代码中将按钮ID更改为类,因为您有一个多按钮

HTML : <table> <tr class="temp1"> <td> <a class="cart_remove">Remove1</a> </td> </tr> <tr class="temp2"> <td> <a class="cart_remove">Remove2</a> </td> </tr> </table> jQUERY: $( document ).ready(function() { $(".cart_remove").click(function(){ $(this).parent().parent().remove(); });

});

试试这个我希望它对你有所帮助

you need to change button id to class in your code just because of you are having a multiple button

HTML : <table> <tr class="temp1"> <td> <a class="cart_remove">Remove1</a> </td> </tr> <tr class="temp2"> <td> <a class="cart_remove">Remove2</a> </td> </tr> </table> jQUERY: $( document ).ready(function() { $(".cart_remove").click(function(){ $(this).parent().parent().remove(); });

});

try this i hope it help to you

更多推荐

本文发布于:2023-08-05 05:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1428566.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单击   按钮   项目   jQuery   Click

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!