javascript - 上标计算 Javascript 变量

标签 javascript variables arithmetic-expressions calculation

我正在使用 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/

相关文章:

java - 如何将字符串传递给不同的方法

recursion - Prolog::f(x) 递归

c - 需要有关评估给定表达式的解释

c++ - 为什么这些函数会截断返回值?

javascript - ViewModel 的 Qunit 测试

javascript - 与 NaN 的比较没有按我预期的方式工作?

javascript - 如何通过添加/删除 Angular 输入来管理焦点/光标位置?

javascript - 根据服务器时间创建倒计时

java - 为什么我在尝试使用局部变量时收到 "cannot find symbol"错误?

variables - Erlang 中的匿名变量