|
|
|
รบกวนช่วยแนะนำการใช้ JavaScript ในการบวกลบตัวเลขด้วยคะ |
|
|
|
|
|
|
|
ลองไปนั่งแกะดูครับ
Code (PHP)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>score</title>
</head>
<body>
<form>
<p>score</p>
<input type="text" class="scoreInput"><br>
<input type="text" class="scoreInput"><br>
<input type="text" class="scoreInput"><br>
<input type="text" class="scoreInput"><br>
<button onclick="calc();return false;">calc</button> <button onclick="resetCalc();return false;">reset</button>
<hr>
<p>result</p>
<label>100-96 </label><input type="text" id="result1" value="0"><br>
<label>95-91 </label><input type="text" id="result2" value="0"><br>
<label>90-86 </label><input type="text" id="result3" value="0"><br>
<label>85 </label><input type="text" id="result4" value="0"><br>
</form>
<script>
//input element
var inputScore = document.getElementsByClassName('scoreInput');
//total element
var loop = inputScore.length;
/*
* calculator score
*/
function calc(){
//add event
for(i=0;i<loop;i++){
var val = inputScore[i].value;
switch(true){
case 101 > val && val > 95:
document.getElementById('result1').value = parseInt(document.getElementById('result1').value) + 1;
break;
case 96 > val && val > 90:
document.getElementById('result2').value = parseInt(document.getElementById('result2').value) + 1;
break;
case 91 > val && val > 85:
document.getElementById('result3').value = parseInt(document.getElementById('result3').value) + 1;
break;
case 86 > val:
document.getElementById('result4').value = parseInt(document.getElementById('result4').value) + 1;
break;
}
}
}
/*
* reset calc
*/
function resetCalc(){
document.getElementById('result1').value = 0;
document.getElementById('result2').value = 0;
document.getElementById('result3').value = 0;
document.getElementById('result4').value = 0;
}
</script>
</body>
</html>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ช่วยด้วยคะ พี่noMerzy มิวยังทำไม่ได้เลย
|
|
|
|
|
Date :
2017-01-09 16:48:20 |
By :
mew |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|