利用JavaScript实现加减乘除运算
<html xmlns="http:///1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312" /><title>实现加减乘除</title><script type="text/javascript"> function operation(){ //第一个数 var oneNumber = parseInt(document.getElementById("one").value); alert(oneNumber); //第二个数 var twoNumber = parseInt(document.getElementById("two").value); alert(twoNumber); //运算符 var calculate = document.getElementById("select").value; alert(calculate); //计算结果 var result = parseInt(document.getElementById("select").value); /** *计算符号的判断 */ switch(calculate) { case'+':result = oneNumber + twoNumber; break; case'-':result = oneNumber - twoNumber; break; case'*':result = oneNumber * twoNumber; break; case'/':result = oneNumber / twoNumber; break; default:alert("错误"); break; } }</script></head><body> <input type="text" id="one" size="12" style="width:40px; "/> <select id="select"> <option value="+">+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">/</option> </select> <input type="text" id="two" size="12" style="width:40px; "/> = <input type="button" id="three" value="?" style="border:none; background-color:#FFFFFF;" onclick="operation();"/></body></html>