var req1, req2;
var sumq ="";
function add(){
sumq = req1 + req2;
return sumq;
}
function substracte(){
sumq = req1 - req2;
return sumq;
}
function multiplication(){
sumq = req1 * req2;
return sumq;
}
function division(){
sumq = req1 / req2;
}
function count(){
req1 = document.getElementById("txt1").value;
req2 = document.getElementById("txt2").value;
var symbol = document.getElementById("select").vlaue;
if(symbol =='+'){
add();
document.getElementById("fruit").value = sumq;
}
else if(symbol == '-'){
substracte();
document.getElementById("fruit").value = sumq;
}
else if(symbol =='*'){
multiplication();
document.getElementById("fruit").value = sumq;
}
else{
division();
document.getElementById("fruit").value = sumq;
}
//获取第一个输入框的值
//获取第二个输入框的值
//获取选择框的值
//获取通过下拉框来选择的值来改变加减乘除的运算法则
//设置结果输入框的值
}
<!DOCTYPE html> <html> <head> <title> 事件</title> <script type="text/javascript"> var req1, req2; var sumq; function add(req1,req2){ sumq = req1 + req2; debugger return sumq; } function substracte(req1,req2){ sumq = req1 - req2; return sumq; } function multiplication(req1,req2){ sumq = req1 * req2; return sumq; } function division(req1,req2){ sumq = req1 / req2; return sumq; } function count(){ req1 = parseInt(document.getElementById("txt1").value); req2 = parseInt(document.getElementById("txt2").value); var symbol = document.getElementById("select"); var index = select.selectedIndex; var fuhao = select.options[index].value; if(fuhao =='+'){ var value = this.add(req1, req2); document.getElementById("fruit").value = value; } else if(fuhao == '-'){ var value = this.substracte(req1,req2); document.getElementById("fruit").value = value; } else if(fuhao =='*'){ var value = this.multiplication(req1,req2); document.getElementById("fruit").value = value; } else{ var value = this.division(req1,req2); document.getElementById("fruit").value = value; } //获取第一个输入框的值 //获取第二个输入框的值 //获取选择框的值 //获取通过下拉框来选择的值来改变加减乘除的运算法则 //设置结果输入框的值 } </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>