林中誠 動態網頁設計 20121115 期中 林中誠 動態網頁設計 20121115 期中
Ch6_4_4.htm

計算機


1.加法
2.減法
3.乘法
4.除法
 


輸入數字
輸入數字
輸入運算代號

<html>
 
<head>
<meta charset="big5"/>
<title>Ch6_4_4.htm</title>
</head>
<body>
<h2>計算機</h2>
<hr/>

1.加法<br/>

2.減法<br/>

3.乘法<br/>

4.除法<br/>

<hr/>
<form name="myform">
輸入數字 <input type="number" name="aaa" value=><br/>

輸入數字 <input type="number" name="bbb" value=><br/>

輸入運算代號 <input type="number" name="ccc" value=><br/><hr/>

<input type="button" value="測試"onclick="showmessage()">
</form>

<script>
function showmessage()
{
var aaa=parseInt(document.myform.aaa.value);
var bbb=parseInt(document.myform.bbb.value);
var ccc=document.myform.ccc.value;

if (ccc==1)
{
document.write("加法  "+(aaa+bbb)+"<br/>");
}
if (ccc==2)
{
document.write("減法   "+(aaa-bbb)+"<br/>");
}
if (ccc==3)
{
document.write("乘法   "+(aaa*bbb)+"<br/>");
}
if (ccc==4)
{
document.write("除法   "+(aaa/bbb)+"<br/>");
}
}
</script>
</body>
</html>