2012-08-17 76 views
-2

我想创建一个简单的启用/禁用单选按钮分组在窗体上。我曾计划使用复选标记的图像来启用和禁用x。我希望未被点击的元素变灰以清楚选择哪个元素。帮助将不胜感激。如何使用图像作为单选按钮

+0

¿QUE ES老阙usted公顷intentado? – 2012-08-17 17:34:21

+4

我并不是想要劫持你的问题,但我做了很多关于使用图像复选框的可用性研究,这是一场完全灾难。人们只能识别*真实的* HTML复选框。你可以阅读我的经历[这里](http://blog.kitchenpc.com/2012/04/13/the-white-whale-of-usability/)。 – 2012-08-17 17:35:09

+0

@MikeChristensen,有趣的阅读和非常丰富。一如既往的可用性应该是第一位的。 – Annabelle 2012-08-17 17:39:45

回答

3

请尝试以下

JQUERY

$(function() { 
    $('input:radio').each(function() { 
     $(this).hide(); 
     $('<a class="radio-fx" href="#"><div class="radio"></div></a>').insertAfter(this); 
    }); 
    $('.radio-fx').live('click',function(e) { 
     e.preventDefault(); 
      var $check = $(this).prev('input'); 
      $('.radio-fx div').attr('class','radio'); 
      $(this).find('div').attr('class','radio-checked');   
      $check.attr('checked', true); 
    }); 
}); 

CSS

.radio { 
    background: url(radiobutton_no.png) no-repeat; 
    width: 16px; 
    height: 16px; 
} 
.radio-checked { 
    background: url(radiobutton_yes.png) no-repeat; 
    width: 16px; 
    height: 16px; 
}