我正在使用 javascript 进行变量计算,但我不知道如何在变量中使用上标。在一些帮助下Javascript calculations holding variables我学会了一般如何进行计算,但我的新问题是如何使用上标?
<form name="Calcultor" Method="Get" id='form1'>First Number:
<input type="text" name="first" size="35" id="first">+ Second Number:
<input type="text" name="second" size="35" id="second">
<br>Answer:
<input type="text" name="ans" size="35" id="ans" />
<input type="text" name="ans2" size="35" id="ans2" />
<button type="button" onclick="Calculate();">Calculate</button>
</form>
<script>
function Calculate() {
var first = document.getElementById('first').value;
var second = document.getElementById('second').value;
var ans = document.getElementById('ans').value;
var ans2 = document.getElementById('ans2').value;
document.getElementById('ans').value = parseInt(first) + parseInt(second);
document.getElementById('ans2').value = 1.112 - 0.00043499 * parseInt(document.getElementById('ans').value)/*insert ans into a parenthensis*/ + 0.00000055 * parseInt(document.getElementById('ans').value)/*insert ans into a parenthensis and ^2 outside the parenthesis*/ - 0.00028826;
}
</script>
最佳答案
javascript中有一个函数Math.pow()
;
Math.pow(2,4)
给出 2^4 = 16。
Math.pow(2,4);
>16
Math.pow(2,4.1);
>17.148375400580687
关于javascript - 上标计算 Javascript 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46402883/