简体   繁体   English

使用 jQuery 添加到购物车

[英]Add to cart using jQuery

I'm trying to model with add to cart using jQuery.我正在尝试使用 jQuery 将 model 添加到购物车。 but it has a small issue of how can I solve that.但它有一个小问题,我该如何解决。 if I click the mybtn button model shows and work properly but quantity it's not working properly.如果我单击mybtn按钮 model 显示并正常工作,但数量它不能正常工作。 How can I solve that?我该如何解决? Thanks in advance.提前致谢。

 <link href="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.2/jquery.modal.min.css" rel="stylesheet"/> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.2/jquery.modal.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.13.0/js/all.min.js"></script> <body> <div class="shoe single-item hvr-outline-out"> <form method="post" action="#" class="cart"> <input type="hidden" name="id" id="id" id="<%= doc._id%>"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="add" value="1"> <input type="hidden" id="pname_<%= doc._id%>" name="shoe_item" value="<%=doc.product_name%>"> <input type="hidden" id="amount_<%= doc._id%>" name="amount" value="<%=doc.price%>"> </form> <button type="submit" id="myBtn1_<%= doc._id%>" data-id="<%= doc._id%>" value="<%= doc._id%>" class="shoe-cart pshoe-cart myBtn"><i class="fa fa-cart-plus" aria-hidden="true"></i></button> </div> <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button> <br/> <center> <table class="row"> </table> </center> </div> </div> </div> </body> <script type="text/javascript"> $(document).ready(function() { $(".myBtn").click(function() { $('#myModal').modal('show'); }); }); </script> <script type="text/javascript"> var count = 0; $(document).ready(function() { $(".myBtn").click(function() { var id = $(this).data('id'); var p_name = $('.cart').find('#pname_' + id).val(); var count1 = count++; var amount = $('.cart').find('#amount_' + id).val(); var html = "<tr id='tr_'" + id + "><td>" + p_name + "</td><td>" + amount + "</td><td><input type='text' name='count' id='count_" + id + "' size='3' value='" + count + "'></td>/tr>"; var quan = $('.row').find('#count_' + id).val(); if (.quan) { $('.row');append(html). } else { $('#count_' + id);append(count); } }); }); </script>

Add click event after modal show模态显示后添加点击事件

$('#myModal').on('shown.bs.modal', function () {
  $(".myBtn").click(function() {
     //your code here
  });
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM