关于jQuery的更改不适用于可读取输入字段
我的形式有一些字段,如下所示:
$(document).on("change", ".qty2", function() {
var sum1 = 0;
$(".qty2").each(function() {
sum1 += +$(this).val();
});
$("#subtotal").val(sum1);
});
$(document).on("change", "#subtotal", function() {
var subt = $("#subtotal").val();
var tot_price = (subt * 9 / 100);
var divobj = document.getElementById('cgst');
var divobj1 = document.getElementById('sgst');
divobj.value = tot_price;
divobj1.value = tot_price;
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" class="form-control price qty2" id="client_type" required name="price[]">
<input type="text" class="form-control price qty2" id="client_type" required name="price[]">
<input type="text" class="form-control price qty2" id="client_type" required name="price[]">
<input type="text" class="form-control qty1" id="subtotal" required name="subtotal" readonly>
<input type="text" class="form-control qty1" id="cgst" required name="cgst" readonly>
<input type="text" class="form-control qty1" id="sgst" required name="sgst" readonly>
除了第一个输入字段的“价格”之外,所有其他3个都被阅读,当用户进入价格字段时,该值被带到小计,我需要从那里计算SGST和CGST并将其显示在各自的字段中,但是,在我的代码中只有在小计显示器正常工作之前,任何人都可以告诉我如何解决此问题,谢谢
i have some fields in my form, which are like below:
$(document).on("change", ".qty2", function() {
var sum1 = 0;
$(".qty2").each(function() {
sum1 += +$(this).val();
});
$("#subtotal").val(sum1);
});
$(document).on("change", "#subtotal", function() {
var subt = $("#subtotal").val();
var tot_price = (subt * 9 / 100);
var divobj = document.getElementById('cgst');
var divobj1 = document.getElementById('sgst');
divobj.value = tot_price;
divobj1.value = tot_price;
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="text" class="form-control price qty2" id="client_type" required name="price[]">
<input type="text" class="form-control price qty2" id="client_type" required name="price[]">
<input type="text" class="form-control price qty2" id="client_type" required name="price[]">
<input type="text" class="form-control qty1" id="subtotal" required name="subtotal" readonly>
<input type="text" class="form-control qty1" id="cgst" required name="cgst" readonly>
<input type="text" class="form-control qty1" id="sgst" required name="sgst" readonly>
here apart from the first input field 'price', all other 3 are readonly, when user enters something in price field, that value is taken to subtotal, and from there i need to calculate sgst and cgst and display it in their respective fields, however in my code only till subtotal display is working, can anyone please tell me how to fix this, thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是使用html的脚本重写
,如果您有一组字段,请将每个集合包装在DIV中并使用.closest(“ Div”)。查找(“。其他Field”)使此工作在例如购物清单中
Here is a rewrite of YOUR script using YOUR html
If you have SETS of fields, wrap each set in a div and use .closest("div").find(".otherfield") to make this work in for example a shopping list
只需在代码中的#subtototal行上评论变更事件,就可以了。
just comment on change event on #Subtotal lines in your code and you are good to go.