首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

JSP页面里得计算有关问题 求帮助

2012-01-07 
JSP页面里得计算问题求帮助%@ page languagejava importjava.util.* pageEncodingGBK%jsp:dir

JSP页面里得计算问题 求帮助
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<jsp:directive.page import="dao.*"/>
<jsp:directive.page import="domain.*"/>
<%
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 'ka_xiao_record_add.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">
-->

  <style type="text/css">
<!--
.style1 {color: #FF0000}
.style3 {
font-family: Arial, Helvetica, sans-serif;
font-size: 36px;
color: #0000FF;
}
-->
  </style>
   
  </head>
  
  <body>
  <h1 align="center" class="style3"> 卡销售 录入</h1>

  <td align="center">
<form action="ka_xiao" method="post" name="ka_xiao">
<table width="923" border="0" cellspacing="-2" cellpadding="-2" height="329">
<tr>
  <td valign="top"><br></td><td width="28%" height="30" align="center">时&nbsp;&nbsp;间:</td>
  <td width="82%" class="word_grey"><input name="DAY" type="text" id="date" >
  <span class="style1">日期格式:YYYY-MM-DD(请注意填写正确的日期格式)</span> </td>
  </tr>
   
   
  <tr>
  <td valign="top"><br></td><td height="28" align="center">价&nbsp;&nbsp;格:</td>
  <td class="word_grey"><input name="MONEY" type="text" id="" >
  <span class="style1">元/张</span></td>
  </tr>
  <tr>
  <td valign="top"><br></td><td height="28" align="center">总 &nbsp;&nbsp;数</td>
  <td height="28"><input name="AMOUNT" type="text" onblur='autocount()' >
  </td>
  </tr>
  <script type="text/javascript">
  function autocount(){
  var AMOUN=document.getElementById('AMOUN').value;
  var MONEY=document.getElementById('MONEY').value;
   
  document.getElementById('TOTAL_MONEY').value=AMOUN*MONEY;
  }
  </script>


  <tr>
  <td valign="top"><br></td><td height="28" align="center">TOTAL_MONEY:</td>
  <td><input name="TOTAL_MONEY" type="text" id="" readonly="ture" ></td>
  </tr>
  <tr>
  <td valign="top"><br></td><td height="28" align="center" style="padding-left:10px">DIS_TO_MONEY:</td>
  <td class="word_grey"><input name="DISCOUNT_TOTAL_MONEY" type="text" id="" size="50">
  </td>
  </tr>  
  <tr>
  <td valign="top"><br></td><td height="34">&nbsp;</td>
  <td ><input name="Submit" type="submit" value="确定提交" onclick=="return autocount(myform)"><input type="hidden" name="change" value="insert"/>
  <input name="Submit2" type="reset" value="重新填写"></td>
  </tr>
  </table>
</form>
  </body>
</html>


  要求当我输入 价格 总数 之后 TOYALY_MONEY会显示计算出的总价格  



这是JSP 部分代码 谁有时间 帮我看看 能不等达到我想要得效果 会加分得

[解决办法]
不过你需要为那几个元素添加ID属性:<input name="MONEY" type="text" id="MONEY" >
<input id="AMOUNT" name="AMOUNT" type="text" onblur='autocount()' >
<input id="TOTAL_MONEY" name="TOTAL_MONEY" type="text" id="" readonly="ture" >

另外,document.getElementById('TOTAL_MONEY').value=AMOUN*MONEY;改成如下形式:
document.getElementById('TOTAL_MONEY').value=Math.floor(AMOUN)*Math.floor(MONEY);
[解决办法]

探讨
不过你需要为那几个元素添加ID属性:<input name="MONEY" type="text" id="MONEY" >
<input id="AMOUNT" name="AMOUNT" type="text" onblur='autocount()' >
<input id="TOTAL_MONEY" name="TOTAL_MONEY" type="text" id="" readon……

[解决办法]
楼主 你狠粗心
Java code
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%><jsp:directive.page import="dao.*"/><jsp:directive.page import="domain.*"/><%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 'ka_xiao_record_add.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">-->  <style type="text/css"><!--.style1 {color: #FF0000}.style3 {font-family: Arial, Helvetica, sans-serif;font-size: 36px;color: #0000FF;}-->  </style>    <script type="text/javascript">  function autocount(){  var AMOUN=document.getElementById('[color=#FF0000]AMOUNT[/color]').value;  var MONEY=document.getElementById('MONEY').value;      document.getElementById('TOTAL_MONEY').value=AMOUN*MONEY;  }  </script>      </head>     <body>  <h1 align="center" class="style3"> 卡销售 录入</h1>  <td align="center"><form action="ka_xiao" method="post" name="ka_xiao"><table width="923" border="0" cellspacing="-2" cellpadding="-2" height="329"><tr>  <td valign="top"><br></td><td width="28%" height="30" align="center">时&nbsp;&nbsp;间:</td>  <td width="82%" class="word_grey"><input name="DAY" type="text" id="date" >  <span class="style1">日期格式:YYYY-MM-DD(请注意填写正确的日期格式)</span> </td>  </tr>          <tr>  <td valign="top"><br></td><td height="28" align="center">价&nbsp;&nbsp;格:</td>  <td class="word_grey"><input[color=#FF0000] id="MONEY" [/color]name="MONEY" type="text" id="" >  <span class="style1">元/张</span></td>  </tr>  <tr>  <td valign="top"><br></td><td height="28" align="center">总 &nbsp;&nbsp;数</td>  <td height="28"><input[color=#FF0000] id="AMOUNT" [/color]name="AMOUNT" type="text" onblur='autocount()' >  </td>  </tr>  <tr>  <td valign="top"><br></td><td height="28" align="center">TOTAL_MONEY:</td>  <td><input[color=#FF0000] id="TOTAL_MONEY" [/color]name="TOTAL_MONEY" type="text" id="" readonly="ture" ></td>  </tr>  <tr>  <td valign="top"><br></td><td height="28" align="center" style="padding-left:10px">DIS_TO_MONEY:</td>  <td class="word_grey"><input name="DISCOUNT_TOTAL_MONEY" type="text" id="" size="50">  </td>  </tr>     <tr>  <td valign="top"><br></td><td height="34">&nbsp;</td>  <td ><input name="Submit" type="submit" value="确定提交" onclick=="return autocount(myform)"><input type="hidden" name="change" value="insert"/>  <input name="Submit2" type="reset" value="重新填写"></td>  </tr>  </table></form>  </body></html> 

热点排行