|
|
|
javascript Radio Button ที่เป็นการวงกลม หรือ สี่เหลี่ยม รูปที่เค้าต้องการได้ใหมครับ |
|
|
|
|
|
|
|
ลองๆแต่งดูด้วย css ครับ
http://code.stephenmorley.org/html-and-css/styling-checkboxes-and-radio-buttons/
|
|
|
|
|
Date :
2014-12-15 19:39:27 |
By :
meannerss |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
css ไม่คล่องครับ ผมใช้แบบนี้ ก็เอาไว้เป็นทางเลือก เป็นแนวคิดก็แล้วกันนะครับ เพื่อทำอย่างอื่น
Code (PHP)
<?php
if(isset($_REQUEST['rdo1'])){
$req=print_r($_REQUEST, true);
}else $rep='';
function get_file( $fn ){
$size = getimagesize($filename);
$fz=filesize($fn);
$f=fopen($fn, 'r'); $txt=base64_encode(fread($f, $fz)); fclose($f);
$ret='data:'.$size['mime'].';base64,'.$txt;
return $ret;
}
//$img=get_file( 'bt_close.gif');
//$img_over=get_file( 'bt_close_over.gif');
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Radio Sample</title>
<style>
.rdo1{}
#rdo1:hover
</style>
<script src="../jquery-2.1.1.min.js"></script>
<script>
function show( id ){
switch(id){
case 0: alert( '1 ='+ (frm.rdo1.item(0).checked? 'true' : 'false')); break;
case 1: alert( '2 ='+ (frm.rdo2.item(0).checked? 'true' : 'false')); break;
case 2: alert( '3 ='+ (frm['rdo[0]'].item(0).checked? 'true' : 'false')); break;
case 3: alert( '4 ='+ (frm['rdo[1]'].item(0).checked? 'true' : 'false')); break;
}
}
var img='data:;base64,R0lGODlhFQAVAPcAAP+gev+LYv+OZv+Ubf+WcP+efP+gfv+FXP+NZv+OaP+QbP+Tb/+Vcf+WdP52UP52Uf58Vv5/Wv6BXv6EYP6GZP'+ '+GZf+JZ/+Jaf+MbP+afP+afv+cfvxrR/5/X/18Xv+CYv6FZv+RdP+Tef+VfP+WfPZhQfdjQ/dlRfhqSvdqS/ZsTvZsT/ZtUfZuUfVuUv97X/99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q9/mbGGnpVogrCAm6+Bm5VlgrB/nK9+m7CAna+BnLCCnbCDnrCEn7GGobCFoK+Dn7GHo7KK'+ 'pbGJpLGKpbGLprGNp7KPqLKPq7KQrLKUr7OVsrKVsbOWs7OZtbSbt7SbubScuv///wAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'+ 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'+ 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH5BAEAA'+ 'MMALAAAAAAVABUAAAj/AIcJHEiwoEGBuEZNegSIDh0wYMKEAQLESQ8YgQbi+gVs1y1ar1yxWmVKVCRGivRwyXJKIKxgwnrhqiULVixVqlJ9wqSIUBs0'+ 'lASG4uVLV61XrUp9yoQJkqJBcNxwwWNJoKRcuWoJXIppEaE3bgRu0ZLHk0BGs2zJGshzzxs2A5eQNTvMzytZrlQNFKQnrEAlctdcEuinlUhUmgbCGRgjhx'+ 'IeagYPi1MKZ6pNmArukBGjM5ZKAr1ECkV6EyM/A3+oSHHiRIzPArsw4hSKU6RHBVeEyHDhgo5EAp8cisSJk6OBYgZuwNDgAgzgw2bQQeSI00A5ZIIMd'+ 'JDAAog7AlUghfmDaKCdMlVueBgowMCHKwJFDKliR2AdO2eOqI8gMEABCvANk4ELRlRxxhlVVJHEDSZMsAABA/gHoEAakGCDEUhYgQQSOLxQggQQKN'+ 'AeABWkIZAZLNRQBBVjTEGEEDS00MEIHDyAAAMokDJQJ33MYUgjhhRSCB9fSAFFFE34wAQoBzXZZEAAOw==';
</script>
</head>
<body>
<pre><?=$req?></pre>
<form name=frm >
radio ชุดที่ 1<span class="expa" data-id="set1">+</span><br>
<div id="set1" style="display: none">
<input type=radio name='rdo1' value=1 onclick=" show(0)" > เลือกค่า 1<br>
<input type=radio name='rdo1' value=2 onclick=" show(0)" > เลือกค่า 2<br>
</div>
radio ชุดที่ 2<span class="expa" data-id="set2">+</span><br>
<div id="set2" style="display: none">
<input type=radio name='rdo2' value=1 onclick=" show(1)" > เลือกค่า 1<br>
<input type=radio name='rdo2' value=2 onclick=" show(1)" > เลือกค่า 2<br>
</div>
radio ชุดที่ 3<span data-id="set3">+</span><br>
<div id="set3" style="display: none">
<input type=radio name='rdo[0]' value=1 onclick=" show(2)" > เลือกค่า 1<br>
<input type=radio name='rdo[0]' value=2 onclick=" show(2)" > เลือกค่า 2<br>
</div>
radio ชุดที่ 4<span data-id="set4">+</span><br>
<div id="set4" style="display: none">
<input type=radio name='rdo[1]' value=1 onclick=" show(3)" > เลือกค่า 1<br>
<input type=radio name='rdo[1]' value=2 onclick=" show(3)" > เลือกค่า 2<br>
</div>
<button type="submit">Submit</button>
</form>
<script>
$(document).ready(function(e) {
$('.img_radio').mouseover(function(e) {
var rdo=$('#'+$(this).attr('data-id') );
if( $( rdo ).prop('checked'))
$(this).attr('src', $(this).attr('data-img'));
else
$(this).attr('src', $(this).attr('data-img_over'));
}).mouseout(function(e) {
var rdo=$('#'+$(this).attr('data-id') );
if( $( rdo ).prop('checked'))
$(this).attr('src', $(this).attr('data-img_over'));
else
$(this).attr('src', $(this).attr('data-img'));
}).click(function(e) {
var xid=$(this).attr('data-id');
$('.img_radio').each(function(index, ele) {
//clear all check not this
if($( ele ).attr('data-id')!==xid) $(ele).attr('src', $(ele).attr('data-img'));
});
// set_checke
$($('#'+$(this).attr('data-id') )).prop('checked', true );
$(this).attr('src', $(this).attr('data-img_over'));
});
//*/
$('.img_radio2').mouseover(function(e) {
var rdo=$('#'+$(this).attr('data-id') );
$(this).attr('src', $( rdo ).prop('checked') ? img : img_over );
}).mouseout(function(e) {
var rdo=$('#'+$(this).attr('data-id') );
$(this).attr('src', !$( rdo ).prop('checked') ? img : img_over );
}).click(function(e) {
var xid=$(this).attr('data-id');
$('.img_radio2').each(function(index, ele) {
//clear all check not this
if($( ele ).attr('data-id')!==xid) $(ele).attr('src', img );
});
// set_checke
$($('#'+$(this).attr('data-id') )).prop('checked', true );
$(this).attr('src', img_over);
});
$('span').click(function(e) {
var id=$(this).attr('data-id');
$('#'+id).toggle(500);
});
});
</script>
<form>
<label>Set 5</label><br>
<input type="radio" name="rdx" id="rdo1" /><img src="bt_close.gif" class='img_radio' data-id='rdo1' data-img="bt_close.gif" data-img_over="bt_close_over.gif" /> TEST1<br>
<input type="radio" name="rdx" id="rdo2" /><img src="bt_close.gif" class='img_radio' data-id='rdo2' data-img="bt_close.gif" data-img_over="bt_close_over.gif" /> TEST2<br>
<input type="radio" name="rdx" id="rdo3" /><img src="bt_close.gif" class='img_radio' data-id='rdo3' data-img="bt_close.gif" data-img_over="bt_close_over.gif" /> TEST2<br>
<label>Set 5</label><br>
<input type="radio" name="rdx1" id="rdo4" /><img src="bt_close.gif" class='img_radio2' data-id='rdo4' /> TEST4<br>
<input type="radio" name="rdx1" id="rdo5" /><img src="bt_close.gif" class='img_radio2' data-id='rdo5' /> TEST5<br>
<input type="radio" name="rdx1" id="rdo6" /><img src="bt_close.gif" class='img_radio2' data-id='rdo6' /> TEST6
</form>
</body>
</html>
|
|
|
|
|
Date :
2014-12-15 22:48:47 |
By :
Chaidhanan |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|