我在表格中有发票表格。我想在字段中添加数量时计算每个项目的总数。我列出的项目数量为空但具有项目的数量。我想只在我向现场添加数量时得到总数。目前我已经能够计算没有数量的总数。 请使用此链接enter link description here
$dbServer = $OctopusParameters["DBServer"]
$dbUser = $OctopusParameters["DBUser"]
$dbPass = $OctopusParameters["DBPass"]
Write-Host ("Running migration " + $dbServer)
$CMD = ".\Resources\migrate.exe"
$arg1 = '--assembly "Database\bin\Debug\Database.dll" --provider sqlserver2014'
$arg2 = '--connection "data source=$dbServer;initial catalog=MyDB;user id=$dbUser;password=$dbPass;persist security info=true;MultipleActiveResultSets=True" -o'
& $CMD $arg1 $arg2
Write-host("Migration finished " + $dbServer)
答案 0 :(得分:0)
以下代码将添加在标记为" Total"的只读输入字段中显示数量*金额的总和。注意:通常class
应该用于多个元素,id
应该对每个元素都是唯一的。如果您希望金额也是只读字段,只需在定义的值之后立即添加关键字readonly
。我使用onBlur
代替onFocus
来允许用户在值发生变化之前对其进行编辑。
function findTotal(){
var arr = document.getElementsByName('qty');
var scale = document.getElementsByName('num');
var tot = 0;
for(var i=0;i<arr.length;i++){
if(arr[i].value != "" && scale[i].value != ""){
tot += parseInt(scale[i].value) * parseInt(arr[i].value);
}
}
document.getElementById('total').value = tot;
}
&#13;
<table width="82%" class='table borderless'>
<tr>
<td>ITEM</td>
<td>Quantity</td>
<td>Amount</td>
</tr>
<tr>
<td width="15%">Saddle (75mm x 3/4) : </td>
<td width="11%">
<input value = 0 type="text" onBlur="findTotal()" name="num"> </td>
<td ><input onBlur()="findTotal()" type="text" name="qty" value="55"/></td>
</tr> <tr>
<td width="15%">Ferrule (19mm) : </td>
<td width="11%">
<input value = 0 type="text" onBlur="findTotal()" name="num"> </td>
<td ><input onBlur="findTotal()" type="text" name="qty" value="60"/></td>
</tr> <tr>
<td width="15%">HDPE Pipe (25mm) : </td>
<td width="11%">
<input value = 0 type="text" onBlur="findTotal()" name="num"> </td>
<td ><input onBlur="findTotal()" type="text" name="qty" value="4.5"/></td>
</tr> <tr>
<td width="15%">Stopcock (19mm) : </td>
<td width="11%">
<input type="text" name="num" value = 0 onBlur="findTotal()"> </td>
<td ><input onBlur="findTotal()" type="text" name="qty" value="45"/></td>
</tr>
<tr>
<td>Total: </td>
<td><input type="text" id='total' value=""readonly></input></td>
</tr>
</table>
<button type="submit" name="process" class="btn btn-primary" id="submit" onclick="findTotal()">Submit Estimate</button>
&#13;