我是 JavaScript 新手,我知道我的代码很奇怪,我该如何解决这个问题?另外,如何在函数中调用函数?我想将所有值转换为数字或浮点数并调用解决方案。
<script type="text/javascript">
function Math(){
var firstNumber = document.getElementById("firstnumber");
var secondNumber = document.getElementById("secondnumber");
this.add = function(){
var fN = Number( firstNumber.value );
var sN = Number( secondNumber.value );
return ( fN + sN );
}
this.sub = function(){
var fN = Number( firstNumber.value );
var sN = Number( secondNumber.value );
return ( fN - sN );
}
this.div = function(){
var fN = Number( firstNumber.value );
var sN = Number( secondNumber.value );
return ( fN - sN );
}
this.mul = function(){
var fN = Number( firstNumber.value );
var sN = Number( secondNumber.value );
return ( fN * sN );
}
}
var myNewMath = new Math();
</script>