我的表单中有一个文本框数组,我需要在输入价格和 % 时根据百分比计算成本价格,cp 是用 mouseup 事件计算的
sp1(name = price[] class = price) %(class = perc) cp1(name = cost[] class = cost)
sp2(name = price[] class = price) %(class = perc) cp2(name = cost[] class = cost)
sp3(name = price[] class = price) %(class = perc) cp3(name = cost[] class = cost)
sp4(name = price[] class = price) %(class = perc) cp4(name = cost[] class = cost)
sp5(name = price[] class = price) %(class = perc) cp5(name = cost[] class = cost)
这是我的jQuery代码
$(function(){
var price = document.getElementsByClassName('price')[0];
var taxAmount = document.getElementsByClassName('cost')[0];
var tax = document.getElementsByClassName('perc')[0];
tax.onblur = function() {
var taxAmount1= parseFloat(price.value) * parseFloat(tax.value) / 100;
var tt = parseInt(price.value)-parseInt(taxAmount1);
taxAmount.value=tt;
}
});
但这仅计算第一个文本框我如何为整个文本框数组执行此操作,并且我正在使用数组,因为我想在 php 中提交此表单。
将不胜感激任何帮助。