使用jquery进行更改后,jquery命令未刷新

时间:2012-06-13 07:36:54

标签: jquery html

我已经制作了一个购物车,购物车已经删除了商品按钮,但jQuery无法从购物车中删除商品。我错过了一些基本的东西吗?

我已将类remove1提供给删除按钮图像并使用以下jQuery ...即使我没有收到警报。

HTML:

<img src='remove.gif' class='remove1'>

JS:

$(".remove1").click(function(){
    alert("hii");
    $(this).parent().remove();
});

3 个答案:

答案 0 :(得分:1)

$(document).ready(function(){
 $("body").delegate('.remove1','click',function(){
              alert("hii");
              $(this).parent().remove();
              });
});

答案 1 :(得分:0)

如果您正在动态添加按钮,请尝试此操作(需要更新版本的jQuery):

$(document).on("click",".remove1", function(){
    alert("hii");
    $(this).parent().remove();
});

另外,你需要使用委托。

答案 2 :(得分:0)

试试这个

$(".remove1").live('click', function(){
    alert("hii");
    $(this).parent().remove();
});