关于JS中的size运算问题
<!DOCTYPE html><html>
<head>
<meta charset="utf-8" />
<title>四则运算</title>
</head>
<body>
<p>整数1:<input id="num1" type="text"></p>
<p>整数2:<input id="num2" type="text"></p>
<p>
<input type="button" value="相加" onclick="calc(this)" >
<input type="button" value="相减" onclick="calc(this)" >
<input type="button" value="相乘" onclick="calc(this)" >
<input type="button" value="相除" onclick="calc(this)" >
</p>
<p>结果:<input id="result" type="text" readonly /></p>
<script type="text/javascript">
function calc( func ){
if(func.value == '相加'){
document.getElementById("result").value =(parseFloat(document.getElementById('num1').value)+parseFloat(document.getElementById('num2').value));
}
if(func.value == '相减'){
document.getElementById("result").value =(parseFloat(document.getElementById('num1').value)-parseFloat(document.getElementById('num2').value));
}
if(func.value == '相乘'){
document.getElementById("result").value =(parseFloat(document.getElementById('num1').value)*parseFloat(document.getElementById('num2').value));
}
if(func.value == '相除'){
document.getElementById("result").value =(parseFloat(document.getElementById('num1').value)/parseFloat(document.getElementById('num2').value));
}
}
</script>
</body>
</html>
如何用add() sub() mul() div()来实现上述过程
页:
[1]