|
|
|
โชว์ checkbox ตามหมวดที่คลิกจาก radio button ต้องเขียนฟังก์ชั่นยังไงครับ |
|
|
|
|
|
|
|
ใช้ JS switch
Code (PHP)
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$(':radio').change(function() {
switch (this.id) {
case 'radio1':
$('#checkbox6, #checkbox8').attr('checked', true);
$(':checkbox:not(#checkbox6, #checkbox8)').attr('checked', false);
break;
case 'radio2':
$('#checkbox2, #checkbox4').attr('checked', true);
$(':checkbox:not(#checkbox2, #checkbox4)').attr('checked', false);
break;
case 'radio3':
$('#checkbox1, #checkbox7').attr('checked', true);
$(':checkbox:not(#checkbox1, #checkbox7)').attr('checked', false);
break;
case 'radio4':
$('#checkbox3, #checkbox5').attr('checked', true);
$(':checkbox:not(#checkbox3, #checkbox5)').attr('checked', false);
}
});
});
</script>
</head>
<body>
หนึ่ง :<input type="radio" id="radio1" name="radio"/><br>
สอง :<input type="radio" id="radio2" name="radio"/><br>
สาม :<input type="radio" id="radio3" name="radio"/><br>
สี่ :<input type="radio" id="radio4" name="radio"/><br><br>
<hr>
3 :<input type="checkbox" id="checkbox1"/><br>
two :<input type="checkbox" id="checkbox2"/><br>
four :<input type="checkbox" id="checkbox3"/><br>
2 :<input type="checkbox" id="checkbox4"/><br>
4 :<input type="checkbox" id="checkbox5"/><br>
1 :<input type="checkbox" id="checkbox6"/><br>
three :<input type="checkbox" id="checkbox7"/><br>
one :<input type="checkbox" id="checkbox8"/><br>
</body>
</html>
https://www.w3schools.com/code/tryit.asp?filename=GF4IM38Y3G9B
|
|
|
|
|
Date :
2020-05-24 13:20:46 |
By :
PhrayaDev |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 04
|