<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="entity.goods"%>
<%@page import="java.util.Map.Entry"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'shoping.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<link type="text/css" rel="stylesheet" href="css/style.css" />
<script type="text/javascript" src="scripts/function.js"></script>
<script type="text/javascript">
function getTotal(){       
              var  price=document.getElementsByName("monery");       
              alert("ss");     
              var  num=document.getElementsByName("num");           
              var total=0;             
              for(var  i=0;i<price.length;i++){            
                total= total+ price[i].value*num[i].value;
              }            
           document.getElementById("count").innerHTML=total           
       }                        
       function  checkNum(tnumId, numId){
            var  tnum=document.getElementById(tnumId).value;
           var  num=document.getElementById(numId).value;          
            if(num-tnum>0){          
              alert("没有这么多个库存");             
              document.getElementById(numId).value=tnum;
            }          
            getTotal();
       }
       function add(gdnumid,gdcountid){
       alert("家");
        var num=document.getElementById(gdnumid).value;
        var kc=document.getElementById(gdcountid).value;     
        if( parseInt(ku)>parseInt(kc)){
        var kk=parseInt(kk)+parseInt(1);
        document.getElementById(gdnumid).value=kk;
        }
      function cut(gdnumid,gdcountid){
      alert("减")
        var num=document.getElementById(gdnumid).value;
        var kc=document.getElementById(gdcountid).value;  
        if( parseInt(ku)>parseInt(kc)){
        var kk=parseInt(kk)-parseInt(1);
        document.getElementById(gdnumid).value=kk;
        }
       }
       
</script>
  </head>
  <body onload="getTotal()">   
    <div id="position" class="wrap">
您现在的位置:<a href="index.jsp">易买网</a> &gt; 购物车
</div>
<div class="wrap">
<div id="shopping">
<form action="shopping-result.html">
<table>
<tr>
<th>商品名称</th>
<th>商品图片</th>
<th>商品价格</th>
<th>购买数量</th>
<th>当前库存</th>
<th>操作</th>
</tr>
     <% Object obj=session.getAttribute("username");
   if(obj==null){
   %>
   <script type="text/javascript">
   window.alert("你当前未登陆,请登录在购买");
   window.location.href="qtlogin.jsp";
   </script>
   <%
   }else{
   Map mp=(Map)session.getAttribute("shop");
   Map mm=(Map)session.getAttribute("count");
   if(mp==null){%>
   <script type="text/javascript">
   window.alert("亲,你还未购过物!");
   window.location.href="index.jsp";
   </script>
   <%}else{                                                
                Set   entrys=mp.entrySet();               
                Iterator  it=entrys.iterator();                
                while(it.hasNext()){               
                      Map.Entry   e=(Map.Entry)it.next();                     
                      int id=(Integer)e.getKey();                  
                          goods gd=(goods)e.getValue();%>
                        <tr>
                        <td><%=gd.getGoodName()%></td>
                        <td><img src="imagesport/<%=gd.getGoodImg()%>" width="200px"></td>
                        <td>¥<input type="text" value="<%=gd.getGoodPrice()%>" name="monery" readonly="readonly"></td>
                        <td> <input type="button"value="+" onclick="a()">
                        <input id="gdnum<%=gd.getGoodid()%>" name="num" type="text" value="<%=mm.get(id)%>">
                        <input type="button" value="-" onclick="cut('gdnum<%=gd.getGoodid()%>','gdcount<%=gd.getGoodid()%>')"></td>
                        <td><input id="gdcount<%=gd.getGoodid()%>" type="text" value="<%=gd.getGoodstock()%>" readonly="readonly"></td>
                        <td><a href="">删除</a></td>
                        </tr>                    
           <%}}}%>
           
</table>
你当前购物总价是:¥<div id="count">元</div>
<div class="button"><input type="submit" value="" /></div>
</form>
</div>
</div>

       
  </body>
</html>
那个onlick事件老是不执行啊

解决方案 »

  1.   

    是那个onclick事件的最好能把错误代码贴出来
    推荐一个java技术站点
    软件开发者社区
      

  2.   

     function add(gdnumid,gdcountid){
      alert("家");
      var num=document.getElementById(gdnumid).value;
      var kc=document.getElementById(gdcountid).value; 
      if( parseInt(ku)>parseInt(kc)){
      var kk=parseInt(kk)+parseInt(1);
      document.getElementById(gdnumid).value=kk;
      }这个函数少了个 “}”
      

  3.   

    onclick="a()"->onclick="add()"并且加入参数
      

  4.   


    js的问题,最好的办法是用火狐浏览器,使用firebug调试,一下就看出那里出现语法错误了。