我想为我的表单进行dinamically javascript计算,我不想为每一行做这个。我试图用while循环来做这个,但是在我的例子中(i)当我这样添加时,变量无法识别:
( '<%=FV.FindControl("txt_OBR_P_1_1" + "_" & i )
<script language="javascript">
$(function () {
$(document).on("keyup", "input[type=text]", function() {
var i = 1;
while (i < 10) {
var txt_OBR_P_1_1 = parseFloat(document.getElementById('<%=FV.FindControl("txt_OBR_P_1_1" & "_" & i).ClientID%>').value.replace(/\,/g, '')) || 0
var txt_OBR_P_1_2 = parseFloat(document.getElementById('<%=FV.FindControl("txt_OBR_P_1_2" & "_" & i).ClientID%>').value.replace(/\,/g, '')) || 0
var txtKOL3 = txt_OBR_P_1_1 + txt_OBR_P_1_2;
if (txtKOL3 === 0 || txtKOL3 === Infinity || isNaN(txtKOL3)) {
txtKOL3 = $('#' + '<%:FV.FindControl("txtKOL3" & "_" & i).ClientID%>').val("");
}
else {
txtKOL3 = $('#' + '<%:FV.FindControl("txtKOL3" & "_" & i).ClientID%>').val(txtKOL3.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,'));
}
i++;
}
})
})
</script>