doujishan2247 2015-08-19 06:21
浏览 36
已采纳

如何将Addtocart按钮限制为每个项目仅单击一次或单击后禁用

I have a table and has rows that have an addtocart button per row/item

        $( $table ).delegate(".Addtocart", "click", function() {
            var itemNo = $(this).closest('tr').find('td.itemNo').html();
            var selected_item = $(this).closest('tr').find('td.itemdescr').html();
            var remaining_qty = $(this).closest('tr').find('td.currqty').html();
            var unitPrice = $(this).closest('tr').find('td.unit_price').html();
            var amount = $(this).closest('tr').find('td.Amount').html();
            $("#action").val('add');
            $('#itemNo').val(itemNo);
            $('#selected_item').val($.trim(selected_item));
            $('#remaining_qty').val(remaining_qty);
            $('#unitPrice').val(unitPrice);
            $('#amount').val(amount);
            $('#myModal').modal('show');
        }); 

I want to disable that button on that item after i added it on my Cart List

for example:

Vinegar Addtocart
Sugar Addtocart
Salt Addtocart

Now I want to add vinegar in my cart list. After I added the vinegar, the addtocart button on that vinegar has been disabled. How? Thank you

  • 写回答

1条回答 默认 最新

  • douyou7797 2015-08-19 06:22
    关注

    Why don't you hide the button after clicking it...

    Another option is to use a class based filter like

    $($table).delegate(".Addtocart:not(.clicked)", "click", function () {
        var itemNo = $(this).closest('tr').find('td.itemNo').html();
        var selected_item = $(this).closest('tr').find('td.itemdescr').html();
        var remaining_qty = $(this).closest('tr').find('td.currqty').html();
        var unitPrice = $(this).closest('tr').find('td.unit_price').html();
        var amount = $(this).closest('tr').find('td.Amount').html();
        $("#action").val('add');
        $('#itemNo').val(itemNo);
        $('#selected_item').val($.trim(selected_item));
        $('#remaining_qty').val(remaining_qty);
        $('#unitPrice').val(unitPrice);
        $('#amount').val(amount);
        $('#myModal').modal('show');
        $(this).addClass('clicked')
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 树莓派与pix飞控通信
  • ¥15 自动转发微信群信息到另外一个微信群
  • ¥15 outlook无法配置成功
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题