【发布时间】:2018-01-18 07:18:34
【问题描述】:
我在这个页面中有两个问题。
问题 1
我有一个文本框和一个表格,当文本框的值与表格中产品id列的值匹配时,数量中的值应该加1。
当我运行调试器时,我得到了值,但 if 语句不起作用。
问题 2
数量的值应该与价格的值相乘,并在总计列中显示结果。乘法适用于第一行,但对于第二行和后面的行它不起作用。为此,我尝试了 ID 和 CLASS
NOTE
所有行都是从后端动态生成的。
提前谢谢..
/*Increase quanity in billing table*/
$(document).ready(function(){
$("#add").click(function () {
var product1 = parseInt(document.getElementById('billing-product-id').value);
var product2 = parseInt(document.getElementById('billing-product-id1').value);
var quanity = parseInt(document.getElementById('billing-quanity').value);
if(product1 === product2 ){
quanity = quanity + 1;
}
});
});
/*billing table total*/
$("#billing-quanity,#billing-price").keyup(function () {
$('#billing-total').val($('#billing-quanity').val() * $('#billing-price').val());
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<!-- Billing Table -->
<div class="container-fluid billing-section">
<table class="table table-striped" id="billing-table">
<form action="" method="post">
<legend>Billing</legend>
<thead>
<tr>
<th>Product ID</th>
<th><input type="text" name="billing-product-id" id="billing-product-id" class="form-control" required></th>
<th><input type="submit" class="btn btn-primary" value="ADD" id="add"></th>
</tr>
</thead>
</form>
<thead>
<tr>
<th>S.no</th>
<th>Product ID</th>
<th>Product Name</th>
<th>Quantity</th>
<th>Price</th>
<th>Total</th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td><input type="number" class="form-control" id="billing-sno" disabled value="1"></td>
<td><input type="number" class="form-control" id="billing-product-id1" disabled value="123"></td>
<td><input type="text" class="form-control" id="billing-product-name" disabled value="shoes"></td>
<td><input type="number" class="form-control" id="billing-quanity" value=""></td>
<td><input type="number" class="form-control" id="billing-price" disabled value="100"></td>
<td><input type="number" class="form-control" id="billing-total" disabled value=""></td>
<td><input type="button" class="btn btn-primary row-delete" value="Delete" ></td>
</tr>
<tr>
<td><input type="number" class="form-control" id="billing-sno" disabled value="1"></td>
<td><input type="number" class="form-control" id="billing-product-id1" disabled value="123"></td>
<td><input type="text" class="form-control" id="billing-product-name" disabled value="shoes"></td>
<td><input type="number" class="form-control" id="billing-quanity" value=""></td>
<td><input type="number" class="form-control" id="billing-price" disabled value="100"></td>
<td><input type="number" class="form-control" id="billing-total" disabled value=""></td>
<td><input type="button" class="btn btn-primary row-delete" value="Delete" ></td>
</tr>
<tr>
<td><input type="number" class="form-control" id="billing-sno" disabled value="1"></td>
<td><input type="number" class="form-control" id="billing-product-id1" disabled value="123"></td>
<td><input type="text" class="form-control" id="billing-product-name" disabled value="shoes"></td>
<td><input type="number" class="form-control" id="billing-quanity" value=""></td>
<td><input type="number" class="form-control" id="billing-price" disabled value="100"></td>
<td><input type="number" class="form-control" id="billing-total" disabled value=""></td>
<td><input type="button" class="btn btn-primary row-delete" value="Delete" ></td>
</tr>
</tbody>
</table>
</div>
【问题讨论】:
-
什么是
.equals?您正在混合使用 java 和 javascript。那么ID在文档中必须是唯一的 -
我现在编辑了请再检查一遍。感谢观看
标签: javascript jquery