<div id="container"> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="" /><br /> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="" /><br /> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="" /><br /> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="" /><br /> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="" /><br /> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="" /><br /> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="" /><br /> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="" /><br /> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="" /><br /> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="" /><br /> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="" /><br /> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="" /><br /> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="" /><br /> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="" /><br /> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="" /><br /> </div>
$(document).ready(function(){ var maxbox = 2,count=0; var container = $("#container") $('input:checkbox',container).click(function(){ count = $('input:checkbox:checked',container).length; if(count > maxbox){ alert('คุณเลือกได้เพียง '+maxbox+' รายการ'); return false; } }); });
<input type="checkbox" name="checkbox[]" id="checkbox[ ]" value=""/> <input type="checkbox" name="checkbox[]" id="checkbox[ ]" value=""/> <input type="checkbox" name="checkbox[]" id="checkbox[ ]" value=""/> <input type="checkbox" name="checkbox[]" id="checkbox[ ]" value=""/> <input type="checkbox" name="checkbox[]" id="checkbox[ ]" value=""/> <input type="checkbox" name="checkbox[]" id="checkbox[ ]" value=""/>
$(document).ready(function(){ $('input[name="checkbox[]"]').click(function(e){ var Max = 2; var Checked = $('input[name="checkbox[]"]:checked').length; if(Checked==Max){ $('input[name="checkbox[]"]').each(function(){ if(!$(this).is(":checked")){ $(this).prop("disabled", true); } }); }else{ $('input[name="checkbox[]"]').each(function(){ $(this).prop("disabled", false); }); } }); });
</head> <script type="text/javascript"> $(document).ready(function(){ $('input[name="checkbox[]"]').click(function(e){ var Max = 2; var Checked = $('input[name="checkbox[]"]:checked').length; if(Checked==Max){ $('input[name="checkbox[]"]').each(function(){ if(!$(this).is(":checked")){ $(this).prop("disabled", true); } }); }else{ $('input[name="checkbox[]"]').each(function(){ $(this).prop("disabled", false); }); } }); }); </script> <body> //ดึงข้อมูลจาก ดาต้าเบส while($objResult = mysql_fetch_array($objQuery)) { ?> <tr> <td> <input type="checkbox" name="checkbox[]" id="checkbox[]" value="<?=$objResult["ReferenceID"];?>" /> </td> <td><?=$objResult["CourseYear"];?></td> <td><?=$objResult["ReferenceID"];?></td> <td><?=$objResult["SubjectID"];?></td> <td><?=$objResult["SubjectName"];?></td> <td><?=$objResult["PrintName"];?></td> </tr> <? }
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง