ssm框架 ajax实现批量删除,和局部添加购物车,购物车总价格
最新推荐文章于 2024-05-19 13:14:09 发布
<script type="text/javascript"> $(function(){ $("#(获取复选框的id)").click(function(){ $("input[name='id']").prop("checked",this.checked); }); }); function del() { var id=[]; $("input[name='id']:checked").each(function(){ id.push($(this).val()); }); if(id.length==0){ alert("请选择您要删除的数据!"); } if(id.length>0){ if(confirm("是否确定删除?")){ $.post( "${pageContext.request.contextPath}(输入删除的方法url)", {"id":id.join(",")}, function(){ alert("删除成功!"); window.location.reload(true); }); } } } </script>
/* 添加购物车 */ @RequestMapping(value = "/addcart",method = RequestMethod.POST) @ResponseBody public String addCart(Cart cart){ cartService.addcart(cart); return "1"; }
$(function () { $(".yy").click(function(){ var names=$(this).parent().parent().children().eq(1).text();//获取表单中某字段数据的属性 var prices=$(this).parent().parent().children().eq(2).text();//获取表单中某字段数据的属性 $.ajax({ type:"post", url:"/cart/addcart.action", data:{sname:names,sprice:prices}, dataType:"json", success:function (data) { if(data==1){ alert("添加成功!"); }else{ alert("添加失败!") } } }); }); });