|
|
|
หาผลรวมของ radio โดยที่ค่าของ radio คือ 0 , 1 , NA |
|
|
|
|
|
|
|
.....
|
|
|
|
|
Date :
2023-10-27 14:20:14 |
By :
mookmixxwipwap |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (JavaScript)
<html>
<head>
<title></title>
<script src="https://code.jquery.com/jquery-3.7.1.js" integrity="sha256-eKhayi8LEQwp4NKxN+CfCh+3qOVUtJn3QNZ0TciWLP4=" crossorigin="anonymous"></script>
</head>
<body>
<input type="radio" name="d1" value="1" > d1 = 1<br>
<input type="radio" name="d1" value="2" > d1 = 2<br>
<br>
<input type="radio" name="d2" value="1" > d2 = 1<br>
<input type="radio" name="d2" value="2" > d2 = 2<br>
Total value 1 = <i id="ttl" >0</i>
<script>
$(document).ready(()=>{
$('input[type=radio]').click(function() {
let n=this.name;
$(`input[name=${n}]`).removeClass('chk');
$(this).addClass('chk');
$('#ttl').html($('.chk[value="1"]').length);
});
});
</script>
</body>
</html>
|
ประวัติการแก้ไข 2023-10-30 21:16:47
|
|
|
|
Date :
2023-10-30 21:15:47 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Code (JavaScript)
$('input[type="radio"]').click(function() {
let vals = $('input[name^="D"]:checked').map(function() {
return this.value;
})
.get()
.filter(val => val !== "NA");
$("#vals").text(vals);
if (vals.length === 0) {
console.log("No countable selections found");
return;
}
console.log("value :" +vals);
let total = vals.reduce((a,b) => (+a) + (+b),0); // convert to int and sum
console.log("total :" +total);
let pct = (total * 100) / vals.length;
console.log("pct :" +pct);
$("[name=totalDall]").val(total.toFixed(0));
$("[name=sumDall]").val(pct.toFixed(0));
});
|
|
|
|
|
Date :
2023-11-01 14:37:17 |
By :
mookmixxwipwap |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|