### [微信小程序实现购物时限购商品的数量(附代码)](https://www.prosaas.cn/article/17172) **Published:** 2018-08-10T06:45:19 **Author:** 5201314 **Excerpt:** 本篇文章给大家带来的内容是关于微信小程序实现购物时限购商品的数量(附代码),有一定的参考价值,有需要的朋友可以… 本篇文章给大家带来的内容是关于微信小程序实现购物时限购商品的数量(附代码),有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。 展示效果如下: ![](https://img-blog.csdn.net/20180809154746368?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2FhYWFhYXl1YW4=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70) 两个底部用的是一个弹框,利用submit\_type的类型不一样来进行区分哪个是单独购买哪个是包邮开团 wxml代码如下: - - + data-submit\_type="{{submit\_type}}"中的submit\_type就是判断是单独还是开团购买 js代码如下: // 增加数量 addCount(e) { // 购买类型,单独购买或拼团购买 let submit\_type = e.target.dataset.submit\_type; var goods\_count = this.data.goods\_count; goods\_count = parseInt(goods\_count) + 1; //debugger if (submit\_type == 2) { // 拼团购买 var limited\_num = this.data.collage.limited\_num; if (goods\_count > limited\_num) { this.showTip('超出限购'); return; } } this.setData({ goods\_count: goods\_count }); }, // 改变数量(input内的值) changeCount(e) { var goods\_count = e.detail.value; let submit\_type = e.target.dataset.submit\_type; if (submit\_type == 1) { var sys\_num = this.data.goods\_num; if (goods\_count > sys\_num) { // 单独购买 this.showTip('库存不足'); return; } } else if (submit\_type == 2) { // 拼团购买 var limited\_num = this.data.collage.limited\_num; if (goods\_count > limited\_num) { this.showTip('超出限购'); return; } } if (!(/^\[\\d\]+\\.?\\d\*$/.test(goods\_count))) { goods\_count = goods\_count.replace(/\\D/g, ''); return goods\_count ? goods\_count : 1; } if (goods\_count < 1) { return 1; } this.setData({ goods\_count: goods\_count }); },  相关推荐: 微信小程序自定义底部tarbar的代码实现 微信小程序实例:实现顶部tab切换以及滑动切换时导航栏会随着移动的效果(代码) 以上就是微信小程序实现购物时限购商品的数量(附代码)的详细内容,更多请关注知企PROSAAS其它相关文章! **Categories:** 后端开发 ---