jquery实现购物车加减的方法
当数据库的库存达到最大值的时候 就会弹出
js代码如下
$(function(){ var t = $("#quantity"); $("#add").click(function(){ if (parseInt(t.val())==({$stock})){ //当$("#min")为1时,$("#min")不可读状态 alert('已达库存最大值') }else { t.val(parseInt(t.val())); t.val(parseInt(t.val())+1); } //当按加1时,解除$("#min")不可读状态 setTotal(); }) $("#min").click(function(){ if (parseInt(t.val())>1) { //判断数量值大于1时才可以减少 t.val(parseInt(t.val())-1) }else{ $("#min").attr("disabled","disabled") //当$("#min")为1时,$("#min")不可读状态 alert('数量最少为1') } setTotal(); })
选鞋码的时候的ajax代码如下
$("#code38").on('click',function () { var bb = $("#code38").val(); var imga= $("#imga").attr('src'); var c=$('#names').text(); var jiage=$('#jiage').text(); var yanse=$("#yanse").text(); var total=$("#total").text(); var quantity=$("#quantity").val(); var style = jiage *quantity // console.log(style); $('#cc').on('click',function () { $.ajax({ type: "post", url: "{:url('admin/details/dda')}", data: { 'bb':bb, 'c':c, 'jiage':jiage, 'yanse':yanse, 'total':total, 'style':style, 'imga':imga, 'quantity':quantity }, dataType: "json" }) }) })
php代码如下
public function dda(Request $request){ $desc = $request->param('jiage'); $title = $request->param('bb'); $name = $request->param('c'); $link = $request->param('yanse'); $total = $request->param('style'); $imga = $request->param('imga'); $quantity = $request->param('quantity'); // $style = $request->param('style'); $Comm = new Comm(); $Comm->name = $name; $Comm->title = $title; $Comm->link = $link; $Comm->desc = $desc; $Comm->style = $total; $Comm->path = $imga; $Comm->num = $quantity; $res = $Comm->save(); if ($res>0){ $this->success('成功1','index/Details/index'); }else{ $this->error('失败1', 'index/Details/index'); } }