购物车

  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  <html xmlns="http://www.w3.org/1999/xhtml">
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  <title>购物车</title>
  <script type="text/jscript">
  function compute(op){
  var num1,num2,num3;
  num1=parseFloat(document.getElementById("txtnum1").value);
  num2=parseFloat(document.getElementById("txtnum2").value);
  num3=parseFloat(document.getElementById("txtnum3").value);
   
  if(op=="合计"){
  document.getElementById("textfield4").value=num1*num2+num3;
  }
  }
   
  </script>
  </head>
   
  <body>
  <table width="885" height="136" border="1" bgcolor="#FF6633" >
  <tr>
  <td height="31" colspan="5"> <h4>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;简易购物车</h4></td>
  </tr>
  <tr>
  <td width="83">商品名称</td>
  <td width="192">数量(件)</td>
  <td width="192">价格(美元)</td>
  <td width="192">运费(美元)</td>
  <td width="192"><form id="form1" name="form1" method="post" action="">
  <input type="button" name="button" id="button" value="合计" onclick="compute('合计')"/>
  </form></td>
  </tr>
  <tr>
  <td>跑跑道具</td>
  <td><form id="form2" name="form2" method="post" action="">
  <input type="text" name="num1" id="txtnum1" />
  </form></td>
  <td><form id="form3" name="form3" method="post" action="">
  <input type="text" name="num2" id="txtnum2" />
  </form></td>
  <td><form id="form4" name="form4" method="post" action="">
  <input name="num3" type="text" id="txtnum3" />
  </form></td>
  <td><form id="form5" name="form5" method="post" action="">
  <input type="text" name="textfield4" id="textfield4" />
  </form></td>
  </tr>
  </table>
  </body>
  </html>
 

你可能感兴趣的:(JavaScript)