标签:
<html>
<head>
<script type="text/javascript" src="1.js"></script>
</head>
<body>
<input type="text" id="num1"/><br/>
<input type="text" id="num2"/><br/>
<input type="text" id="num3"/><br/>
<input type="button" onclick="func1(‘+‘)" value=" + "/>
<input type="button" onclick="func1(‘-‘)" value=" - "/>
<input type="button" onclick="func1(‘*‘)" value=" * "/>
<input type="button" onclick="func1(‘/‘)" value=" / "/>
</body>
</html>
function func1(val){
var a=parseFloat(document.getElementById(‘num1‘).value);
var b=parseFloat(document.getElementById(‘num2‘).value);
if(val==‘+‘){
num3.value=a+b;
}
if(val=="-"){
num3.value=a-b;
}
if(val=="*"){
num3.value=a*b;
}
if(val=="/"){
num3.value=a/b;
}
}
标签:
原文地址:http://www.cnblogs.com/yuanceo/p/5769064.html