<input type="checkbox" rel="1" checked>:<input type="txt1"><br> <input type="checkbox" rel="2" checked>:<input type="txt2"><br> <input type="checkbox" rel="3" checked>:<input type="txt3"><br> <script src="jquery-1.11.1.min.js"></script> <script> $(function(){ $(':checkbox').on('click',function(){ var rel=$(this).attr('rel'); if($(this).prop('checked')==true){ $('input[type=txt'+rel+']').show(); }else{ $('input[type=txt'+rel+']').hide(); } }); }); </script>
$('tr#tritem_1').hide(); $('tr#tritem_2').hide(); $('tr#tritem_3').hide(); $('input[type="checkbox"]').on('change', function(){ $('input[type="checkbox"]').not(this).prop('checked', false); }); jquery เขียนได้แค่นี้อะครับ checkbox จะเลือกได้แค่ 1 อันเท่านั้น <table> <tr id="tritem_1"> <td> <input id="checkbox_item_1" type="checkbox" value="1" name="checkbox_item"/>checkbox 1 <input id="checkbox_item_2" type="checkbox" value="2" name="checkbox_item"/>checkbox 2 <input id="checkbox_item_3" type="checkbox" value="3" name="checkbox_item"/>checkbox 3 </td> </tr> <tr id="tritem_2"> <td> ถ้าเลือก checkbox 1 โชว์ข้อมูลในนี้ tr นี้ </td> </tr> <tr id="tritem_3"> <td> ถ้าเลือก checkbox 2 โชว์ข้อมูลในนี้ tr นี้ </td> </tr> <tr> <td colspan="2"> ถ้าเลือก checkbox 3 โชว์ข้อมูลในนี้ tr นี้ </td> </tr> </table>
<table> <tr> <td> <input type="checkbox" rel="1" checked />checkbox 1 <input type="checkbox" rel="2" checked />checkbox 2 <input type="checkbox" rel="3" checked />checkbox 3 </td> </tr> <tr id="tritem_1"> <td> ถ้าเลือก checkbox 1 โชว์ข้อมูลในนี้ tr นี้ </td> </tr> <tr id="tritem_2"> <td> ถ้าเลือก checkbox 2 โชว์ข้อมูลในนี้ tr นี้ </td> </tr> <tr id="tritem_3"> <td> ถ้าเลือก checkbox 3 โชว์ข้อมูลในนี้ tr นี้ </td> </tr> </table> <script src="jquery-1.11.1.min.js"></script> <script> $(function(){ $(function(){ $(':checkbox').on('click',function(){ var rel=$(this).attr('rel'); if($(this).prop('checked') == true){ $('#tritem_'+rel).fadeIn(1000); }else{ $('#tritem_'+rel).fadeOut(1000); } }); }); }); </script>
เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง