qq_瓶子Aquarius_0
2016-01-17 11:16
<!DOCTYPE html>
<html>
<head>
<title> 事件</title>
<script type="text/javascript">
function count()
{
var text1=document.getElementById("text1").value;
var text2=document.getElementById("text2").value;
var fu=document.getElementById("select").value;
var tu="";
switch(fu)
{
case "+": tu = parseFloat(text1) + parseFloat(text2); break;
case "-":tu=parseFloat(text1) - parseFloat(text2); break;
case "*":tu=parseFloat(text1) * parseFloat(text2); break;
default:tu=parseFloat(text1) / parseFloat(text2); break;
}
//设置结果输入框的值
document.getElementById("fruit").value = tu;
}
</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>
..........txt1 txt2
JavaScript进阶篇
468195 学习 · 21891 问题
相似问题