效果:
事件:当输入完三个文本框后触发blur事件。计算出平均值
说明:调用方法计算出平均值,
代码:
文本框中:
1 <asp:TextBox ID="tblmyd11" Field="lmyd11" TableName="gqls_sy" EnabledAction="(12.*)" CssClass="erp_textbox_short" runat="server" self="ydpj"></asp:TextBox>
JS部分:
1 /********************硬度HRC平均值**************************/ 2 $(function() { 3 $("[self='ydpj']").blur(function() { Getlmpj("11", "21", "31", "41"); }); 4 $("[self='ydpj']").blur(function() { Getlmpj("12", "22", "32", "42"); }); 5 $("[self='ydpj']").blur(function() { Getlmpj("13", "23", "33", "43"); }); 6 $("[self='ydpj']").blur(function() { Getlmpj("14", "24", "34", "44"); }); 7 //螺母 8 function Getlmpj(one, two, three, four) { 9 var avg = 0; 10 var num1 = ChangeFloat($("input[id*=tblmyd" + one + "]").val()); 11 var num2 = ChangeFloat($("input[id*=tblmyd" + two + "]").val()); 12 var num3 = ChangeFloat($("input[id*=tblmyd" + three + "]").val()); 13 if (num1 != 0 && num2 != 0 && num3 != 0) { 14 avg = (num1 + num2 + num3) / 3; 15 $("input[id*=tblmyd" + four + "]").val(RoundValue(avg, 0.1, 1)); 16 } 17 else { 18 $("input[id*=tblmyd" + four + "]").val(""); 19 } 20 } 21 }); 22 function ChangeFloat(data) { 23 if (data != null && data != "") { 24 return parseFloat(data); 25 } 26 else { 27 return 0; 28 } 29 }