<!DOCTYPE html><html> <head> <title> 事件</title> <script type="text/javascript"> function count(){ var x,y,result,o; x=document.getElementById("txt1").value; //获取第一个输入框的值 y=document.getElementById("txt2").value; //获取第二个输入框的值 o=document.getElementById("select").value; //获取选择框的值 switch(o){ case "+": result=parseInt(x)+parseInt(y); break; case "-": result=parseInt(x)-parseInt(y); break; case "*": result=parseInt(x)*parseInt(y); break; default: result=parseInt(x)/parseInt(y); } document.getElementById("fruit")=result; } </script> </head> <body> <input type='text' id='txt1' /> <select id='select'> <option value='+'>+</option> <option value="-">-</option> <option value="*">*</option> <option value="/">/</option> </select> <input type='text' id='txt2' /> <input type='button' value=' = ' onClick="count()" /> <input type='text' id='fruit' /> </body></html>