โค้ดตัวอย่างการกำหนดให้สามารถเลือก input type radio จากการคลิกที่ข้อความ
อ้างอิงด้านหลัง input type radio นั้นๆ
ตัวอย่าง
ตัวอย่างโค้ดทั้งหมด
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" /> <title></title> </head> <body> <style type= "text/css" > .text_for_radio{ cursor:pointer; } </style> <br /> <br /> <div style= "position:relative;margin:auto;width:700px;" > <form id= "form1" name= "form1" method= "post" action= "" > <input type= "radio" name= "choice" id= "radio" value= "1" /> <span class = "text_for_radio" >ข้อความสำหรับทดสอบที่ 1</span><br /> <input type= "radio" name= "choice" id= "radio" value= "2" /> <span class = "text_for_radio" >ข้อความสำหรับทดสอบที่ 2</span><br /> <input type= "radio" name= "choice" id= "radio" value= "3" /> <span class = "text_for_radio" >ข้อความสำหรับทดสอบที่ 3</span><br /> <input type= "radio" name= "choice" id= "radio" value= "4" /> <span class = "text_for_radio" >ข้อความสำหรับทดสอบที่ 4</span><br /> <input type= "radio" name= "choice" id= "radio" value= "5" /> <span class = "text_for_radio" >ข้อความสำหรับทดสอบที่ 5</span><br /> </form> </div> <script type= "text/javascript" > $( function (){ $( ".text_for_radio" ).click( function (){ $(this).prev( "input[name='choice']" ).attr( "checked" , "checked" ); }); }); </script> </body> </html> |