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')
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?