大佬教程收集整理的这篇文章主要介绍了使用jquery自动用数学更新输入字段?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
<input type="text" name="ancho" /> <input type="text" name="alto" /> <input type="text" name="material" />
我需要它输出到这个字段:
<input type="text" name="ml" />
以下是数学方面的等式:
(材料/ 100)/((alto / 100)*(ancho / 100))
提前感谢您的帮助!
// locate all the input fields on the page $(':input') // bind to anything change related (down to keyboard changes so the element // won't need to lose focus,or the user won't have to press enter) .bind('keypress keydown keyup change',function(){ // retrieve the values of the inputs (we also call parseFloat to confirm // we are dealing with numeric values) var acho = parseFloat($(':input[name="acho"]').val(),10),alto = parseFloat($(':input[name="alto"]').val(),matl = parseFloat($(':input[name="material"]').val(),10); // default the end result to an empty @R_675_10495@ng (you'll see // why with the following statement) var v = ''; // confirm that all three values that go in to the equation are // all numbers before we try to perform any math functions. If // all goes well,"v" above will have the actual resulTing value. // if any number is invalid,the "Result" field (ml) gets emptied if (!isNaN(acho) && !isNaN(alto) && !isNaN(matl)){ // your math function v = (matl / 100) / ((alto / 100) * (acho / 100)); } // replace the value of "ml" with our new calculated value $(':input[name="ml"]').val(v.to@R_675_10495@ng()); });
以上是大佬教程为你收集整理的使用jquery自动用数学更新输入字段?全部内容,希望文章能够帮你解决使用jquery自动用数学更新输入字段?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。