肆辻柒
2015-11-28 14:05
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title></title>
<script type="javascript" >
function result(){
var text1=parseInt(document.getElementById('txt1').value);
var text2=parseInt(document.getElementById('txt2').value);
var select=document.getElementById('select').value;
var res='';
if(select == "+"){
res=text1+text2;
}else if(select == "-"){
res=text1-text2;
}else if(select == "*"){
res=text1*text2;
}else{
res=text1/text2;
}
document.getElementById('result').value=res;
}
</script>
</head>
<body>
<form>
计算器
<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" id="but" value="=" onclick="result()" />
<input type="text" id="result" />
</form>
</body>
</html>
找到原因了,因为我用了<form>,但是为什么用了form就不能运行了呢?
JavaScript进阶篇
468060 学习 · 21891 问题
相似问题