標籤
Android
(
1
)
DbVisualizer
(
2
)
html/javascript
(
1
)
java
(
11
)
MySQL
(
1
)
oracle
(
1
)
servlet&jsp
(
3
)
struts
(
2
)
2011年8月19日 星期五
簡易計算機 練習
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=big5">
<title>簡易javascript計算機</title>
</head>
<body background="images/j007.jpg">
a + b: <input id='a' size="4"/> + <input id='b' size="4">
<button onclick="calc();" style="width: 40; height: 27">=</button>
<span id="result"> </span>
<script language="JavaScript">
function calc() {
//parseFloat 會將字串轉換成浮點數
//document.getElementById會取得指定的id名稱物件
var a = parseFloat(document.getElementById('a').value);
var b = parseFloat(document.getElementById('b').value);
document.getElementById('result').innerText = + (a+b);
}
</script><p>
a - b : <input id='a1' size="4"/> <font size="4"> -</font> <input id='b1' size="4">
<button onclick="calc1();" style="width:40; height: 27">=</button>
<span id="result1"></span>
<script language="JavaScript">
function calc1() {
var a1 = parseFloat(document.getElementById('a1').value);
var b1 = parseFloat(document.getElementById('b1').value);
document.getElementById('result1').innerText = + (a1-b1);
}
</script><p>
a * b : <input id='a2' size="4"/> <font size="4"> *</font> <input id='b2' size="4">
<button onclick="calc2();" style="width:40; height: 27">=</button>
<span id="result2"></span>
<script language="JavaScript">
function calc2() {
var a2 = parseFloat(document.getElementById('a2').value);
var b2 = parseFloat(document.getElementById('b2').value);
document.getElementById('result2').innerText = + (a2*b2);
}
</script><p>
a ÷ b : <input id='a3' size="4"/> <font size="4"> ÷</font> <input id='b3' size="4">
<button onclick="calc3();" style="width:40; height: 27">=</button>
<span id="result3"></span>
<script language="JavaScript">
function calc3() {
var a3 = parseFloat(document.getElementById('a3').value);
var b3 = parseFloat(document.getElementById('b3').value);
document.getElementById('result3').innerText = + (a3/b3);
}
</script>
</body>
</html>
訂閱:
張貼留言
(
Atom
)
沒有留言 :
張貼留言