简体   繁体   English

我如何使用math.sqrt进行计算正确?

[英]how can i make my calculation using math.sqrt right?

I just want to get the square root of total2 .. but it won't appear in the selected box .. here is the javascript codes. 我只想获取total2的平方根..但它不会出现在所选框中..这是JavaScript代码。 i'll comment the html codes. 我将注释html代码。

 function myFunction() { var q1 = document.getElementById("qinput1").value; var q2 = document.getElementById("qinput2").value; var q3 = document.getElementById("qinput3").value; var total = parseInt(q1) + parseInt(q2) + parseInt(q3); document.getElementById("ainput3").value=total; var a1 = document.getElementById("ainput1").value; var a2 = document.getElementById("ainput2").value; //from the total we got, lets assign it a variable for further calculation var a3 = document.getElementById("ainput3").value=total; var total2 = parseInt(a1)*parseInt(a2)/ parseInt(a3); document.getElementById("ansA").value = total2; var total3 = math.sqrt(parseInt(total2)); document.getElementById("sqaureD").value = total3; } function myShapes() { document.getElementById('squareA').style.display = document.getElementById('shapes').value == 'Square' ? 'block' : 'none' } 
 <form action="" id="fcalculation"> <fieldset> <legend>Calculation of qu</legend> <label><i>Ultimate bearing capacity</i> <b>(qu) = </b></label> <input id="qinput1" type="text" placeholder="c'NcFcsFcdFci"/> + <input id="qinput2" type="text" placeholder="qNqFqsFqdFqi"/> + <input id="qinput3" type="text" placeholder="½βγNFγsFγdFγi"/> </fieldset> </form> 

it seems that the calculation part at the very end is not working. 似乎最后的计算部分不起作用。 sorry its my first time to code. 对不起,这是我第一次编写代码。

Classname is Math not math 类名是Math而不是math

Try replacing 尝试更换

var total3 = math.sqrt(parseInt(total2,10));

with

var total3 = Math.sqrt(parseInt(total2,10));

Also, looking at your markup, there are no fields with id ainput1 , ainput2 and ainput3 . 另外,查看您的标记,没有ID为ainput1ainput2ainput3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM