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 hereI 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
更多推荐
发布评论