<!DOCTYPE HTML>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>函数</title>
<script type="text/javascript">
function count(){
var result="";
var lw1=document.getElementById("txt1").value;
var lw2=document.getElementById("txt").value;
var operea=document.getElementById("select").value;
switch (operea){
case"+":result=parseFloat(lw1)+parseFloat(lw2);
break;
case"-":result=parseFloat(lw1)-parseFloat(lw2);
break;
case"*":result=parseFloat(lw1)*parseFloat(lw2);
break;
case"/":result=parseFloat(lw1/parseFloat(lw2);
}
document.getElementById("fruit").value=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' onclick=count() value='='/> <!--通过 = 按钮来调用创建的函数,得到结果-->
<input type='text' id='fruit' value=""/>
</body>
</html>
Caballarii
相关分类