文、意如
使用者輸入單價、數量後,計算出總額
#提示:
//抓值xx = document.getElementById("xx").value;
//賦予值document.getElementById("aa").value = totals;
page.html
<html>
<head>
</head>
<body>
單價<input type="text" id="price" name="price"><br>
數量<input type="number" min="0" max="27" id="num"><br>
<button onclick="cal()">計算</button><br>
總價<input type="text" id="total">
</body>
</html>
<script>
function cal() {
pirce = document.getElementById("price").value;
num = document.getElementById("num").value;
totals=pirce*num;
document.getElementById("total").value = totals;
}
</script>
https://codepen.io/yiruatstudio/pen/qBNKreJ
#Javascript-在function()中再呼叫其他function()
<html>
<head> </head>
<body>
A值<input type="text" id="priceA" name="price"><br>
B值<input type="text" id="priceB" name="price"><br>
<button onclick="cal()">計算</button><br>
總價<input type="text" id="total">
</body>
</html>
<script>
function cal() {
pirceA = document.getElementById("priceA").value;
pirceB = document.getElementById("priceB").value;
//呼叫cal2(a,b)
num = cal2(pirceA,pirceB);
document.getElementById("total").value = num;
}
function cal2(a,b){
return a*b;
}
</script>
Yiru@Studio - 關於我 - 意如