前台多个id值的传递(实例)

来源:互联网 发布:东北财经大学会计 知乎 编辑:程序博客网 时间:2024/06/16 09:49

    前台jsp

<SCRIPTtype="text/javascript">

    /*

    i用来记录迭代次数

    j用来标记是否被选中

    */

    function jia(j) {

            var z=Number(document.getElementById("b"+j).value);

            var js=Number(document.getElementById("js").value);

            if (z==0) {

                document.getElementById("b"+j).value=z+1;

                document.getElementById("tj").style.display="";

                document.getElementById("js").value=js+1;

            } else {

                document.getElementById("b"+j).value=z-1;

                document.getElementById("js").value=js-1;

            /*如果没有被选中的目标将不显示提交按钮*/

                if(document.getElementById("js").value==0) {

                    document.getElementById("tj").style.display="none";

                }

            }

    }

        functionchashu() {

        //拿到用户账号

        varuser=document.getElementById("user1").value;

        varleng=Number(document.getElementById("quanbu").value);

        varchuanchang=0;    

        varchuan=newArray();

        vara=0;

        varduoleng=0;

        varduo=document.getElementsByName("duoxuan");

        for( varc = 0; c < duo.length; c++) {

        if(duo[c].checked){

        chuan[chuanchang]=duo[c].value;

        chuanchang++;

        }

        }

        varad="";

        for( var dd= 0; dd < chuan.length; dd++) {

            ad+=String(chuan[dd])+",";

        }

        window.location="my/myshow!updategwc.action?wdusers.user="+user+"&&arr="+ad;

    }

    function chakan() {

        varuser=document.getElementById("user1").value;

        window.location="my/myshow!chakangm.action?wdusers.user="+user;

    }

    function del(id) {

    var user=document.getElementById("user1").value;

        window.location="my/myshow!deletegwc.action?wdusers.user="+user+"&&wdusers.id="+id;

    }

    </SCRIPT>

    <STYLEtype="text/css">

    #chakan{

    cursor:pointer;

    }

    #chakan:HOVER{

    color: red;

}

    body{

            background-image:url("imgs/zxy/a4.jpg");

        }

        #del{

        cursor: pointer;

        }

        #del:HOVER {

    color: red;

}

    #all{

    position:absolute;

    left: 60px;

    top: 200px;

    }

    </STYLE>

  </head>

 

  <body>

  <jsp:includepage="../goods.jsp"></jsp:include><br/><br/><br/><br/><br/><br/><br/><br/><br/>

  <% int i=0;%>

  <% int j=0;%>

  <divid="all">

  <spanid="chakan"onclick="chakan();">查看购买记录</span><br/><br/>

 

  <inputtype="hidden"value="<s:propertyvalue="user"/>"id="user1"/>

    <s:iteratorvalue="list"var="l">

    <div>

    <inputtype="hidden"value="0"id="b<%=++j%>"/>

   <inputtype="hidden"name="wdgw.id"value="<s:propertyvalue="#l.id"/>"id="a<%=++i%>"/>

    <spanonclick="jia(<%=j%>);"><inputtype="checkbox"name="duoxuan"value="<s:propertyvalue="#l.id"/>"/></span>

    货品名称:<s:propertyvalue="#l.goodname"/>

        尺码:<s:propertyvalue="#l.style"/>

        颜色:<s:propertyvalue="#l.color"/>

        数量:<s:propertyvalue="#l.shuliang"/>

        单价: <s:propertyvalue="#l.danjia"/>

        总价:<s:propertyvalue="#l.zongjia"/>&nbsp;

        <SPANid="del"onclick="del(<s:propertyvalue="#l.id"/>);">点击删除</SPAN>

    <br/>

    </div>

    </s:iterator>

    <buttononclick="chashu();"id="tj"style="display: none;">提交</button>

    <inputtype="hidden"value="<%=i%>"id="quanbu"/>

    <inputtype="hidden"value="<%=j%>"id="quanbuj"/>

    <inputtype="hidden"value="0"id="js"/>

    <br/>

    </div>

  </body>

</html>

 

后台action

public String updategwc(){

        //执行支付 执行更改购物车中状态

            String[] arr1=arr.split(",");

            for (inti = 0; i < arr1.length; i++) {

                intid=Integer.parseInt(arr1[i]);

                System.out.println(id);

                //执行更改并拿到被更改的物品数量、名称、颜色、型号

                List l=dao.updategwc(wdusers.getUser(),id);

                for(intj = 0; j < l.size(); j++) {

                    Wdgw w=(Wdgw) l.get(j);

                    int kucun=dao.findwdgoodsku(w.getGoodname(),w.getStyle(),w.getColor());

                    kucun-=Integer.parseInt(w.getShuliang());

                    servicedao.updatewdgoods(w.getGoodname(),w.getColor(),w.getStyle(), kucun);

                }

            }

            return"goumai";

     }

0 0
原创粉丝点击