<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>定义函数</title>
</head>
<body>
<input type="number" id="one" value="2" name="one">
<select id="sel" >
<option value='+'>+</option>
<option value='-'>-</option>
<option value='*'>*</option>
<option value='/'>/</option>
</select>
<input type="number" id="two" value="4" name="two"/>=
<input type="text" id="res" disabled/>
<input type="button" value="计算" onclick="sub2()" />
<style>
input{
50px;
}
</style>
<script type="text/javascript">
function sub2() //定义函数
{
var onen =parseInt(document.getElementById("one").value,10);
var twon =parseInt(document.getElementById("two").value,10);
var seln =document.getElementById("sel").value;
// var resn =document.getElementById("res").value;
if(seln=="+"){
sub=onen+twon;
}
else if(seln=="-"){
sub=onen-twon;
}
else if(seln=="*"){
sub=onen*twon;
}
else{
sub=onen/twon;
}
document.getElementById("res").value=sub;
}
</script>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>定义函数</title>
</head>
<body>
<input type="number" id="one" value="2" name="one">
<select id="sel" >
<option value='+'>+</option>
<option value='-'>-</option>
<option value='*'>*</option>
<option value='/'>/</option>
</select>
<input type="number" id="two" value="4" name="two"/>=
<input type="text" id="res" disabled/>
<input type="button" value="计算" onclick="sub2()" />
<style>
input{
50px;
}
</style>
<script type="text/javascript">
function sub2() //定义函数
{
var onen =parseInt(document.getElementById("one").value,10);
var twon =parseInt(document.getElementById("two").value,10);
var seln =document.getElementById("sel").value;
// var resn =document.getElementById("res").value;
if(seln=="+"){
sub=onen+twon;
}
else if(seln=="-"){
sub=onen-twon;
}
else if(seln=="*"){
sub=onen*twon;
}
else{
sub=onen/twon;
}
document.getElementById("res").value=sub;
}
</script>
</body>
</html>