<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
function ss() {
var text1=document.getElementById("text1").value;
var obj=document.getElementById("gs");
var index = obj.selectedIndex;
var sushu = obj.options[index].value;
//获取下拉框的值
*/
var sushu = document.getElementById("gs").value; //获取下拉框的值
var text3 = document.getElementById("text3");
var rst;
num1 = parseFloat(text1);
num2 = parseFloat(text2);
switch(sushu){
case "+":
rst = num1+num2; break;
case "-":
rst = num1-num2; break;
case "*":
rst = num1*num2; break;
case "/":
rst = num1/num2; break;
}
text3.value=rst; //将得到的值交给第三个下拉框,注意一点:如果上面给text3赋值时直接使用.value,这里给text3赋值是无法传入文本框的。
}
</script>
</head>
<body>
<p><input id="text1" type="text" name="text1" size="5px"/>
<select id="gs" name="gs">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input id="text2" type="text" name="text2" size="5px" />
<input type="button" name="equal" value="=" οnclick="ss();"/>
<input type="text" id="text3" size="5px" readonly/>
</p>
</body>
</html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<script type="text/javascript">
function ss() {
var text1=document.getElementById("text1").value;
var text2=document.getElementById("text2").value;
//下面有两个获取下拉框的值方法,第一个是我自己在网上查的,第二个是老师上课讲的方法
/*var obj=document.getElementById("gs");
var index = obj.selectedIndex;
var sushu = obj.options[index].value;
//获取下拉框的值
*/
var sushu = document.getElementById("gs").value; //获取下拉框的值
var text3 = document.getElementById("text3");
var rst;
num1 = parseFloat(text1);
num2 = parseFloat(text2);
switch(sushu){
case "+":
rst = num1+num2; break;
case "-":
rst = num1-num2; break;
case "*":
rst = num1*num2; break;
case "/":
rst = num1/num2; break;
}
text3.value=rst; //将得到的值交给第三个下拉框,注意一点:如果上面给text3赋值时直接使用.value,这里给text3赋值是无法传入文本框的。
}
</script>
</head>
<body>
<p><input id="text1" type="text" name="text1" size="5px"/>
<select id="gs" name="gs">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input id="text2" type="text" name="text2" size="5px" />
<input type="button" name="equal" value="=" οnclick="ss();"/>
<input type="text" id="text3" size="5px" readonly/>
</p>
</body>
</html>