我想用javacript创建一个库存计算系统,现在我已经创建了它有一些问题是我已经创建了3行1.Purchase,2.Sold,3.Stock。现在我已经设置了当我给出购买价值时和已售出的数量,它将减去并在库存文本框中打印值,然后是下一列库存值也在购买文本框中打印问题是当购买项目变为 nill 时意味着 0 所以我该怎么做才能添加一些数量并重新开始这个流程。编码是。
<html>
<head>
<title>Stock Information</title>
<link rel="stylesheet" type="text/css" href="css/style.css"/>
<script type="text/javascript">
//------------------------------------Date---------------------------------------------
var today = new Date(); //
var dd = today.getDate(); //
var mm = today.getMonth()+1; //January is 0! //
var yyyy = today.getFullYear(); //
today = dd+'/'+mm+'/'+yyyy; //
document.write(today); //
//-------------------------------------------------------------------------------------
//----------------------------------------------------
function program(a,b,c,d,e,f)
{
var total1=a-b;
document.stock.t3.value=total1;
var jump1=document.stock.t3.value;
document.stock.t4.value=jump1;
var total2= c-d;
document.stock.t6.value=total2;
var jump2=document.stock.t6.value;
document.stock.t7.value=jump2;
var total3= e-f;
document.stock.t9.value=total3;
}
</script>
</head>
<body>
<center>
<h1 class="table">Stock Information</h1>
</center>
<table width="800" align="center" class="table1">
<tr>
<th width="260"class="table">Purchase</th>
<th width="260"class="table">Sold</th>
<th width="428"class="table">Stock</th>
</tr>
<form name="stock">
<tr align="center">
<td><input id="t1" type="text" style="width:260px;" class="input1"/></td>
<td><input id="t2" type="text" style="width:260px;" class="input1"/></td>
<td><input id="t3" type="text" style="width:260px;" class="input1" onClick="program(t1.value,t2.value)" readonly/></td>
</tr>
<tr align="center">
<td><input id="t4" type="text" style="width:260px;" class="input1" onClick="program(t1.value,t2.value,t4.value,t5.value)"/></td>
<td><input id="t5" type="text" style="width:260px;" class="input1"/></td>
<td><input id="t6" type="text" style="width:260px;" class="input1" onClick="program(t1.value,t2.value,t4.value,t5.value)" readonly/></td>
</tr>
<tr align="center">
<td><input id="t7" type="text" style="width:260px;" class="input1" onClick="program(value1.value,value2.value,t4.value,t5.value)"/></td>
<td><input id="t8" type="text" style="width:260px;" class="input1"/></td>
<td><input id="t9" type="text" style="width:260px;" class="input1" onClick="program(value1.value,value2.value,t4.value,t5.value,t7.value,t8.value)"readonly/></td>
</tr>
</form>
</table>
</body>
</html>