日期:2014-05-16  浏览次数:20409 次

radio单选按钮替换问题
我想要一组每个都不同单选按钮,就是选中和不选中是两张图片。昨天得到大家的帮助有了这个代码。还差一个问题就是radio{ background-image:url("1.png")得到的效果是在单选按钮下面加了一张图,可是按钮还是有。有没有方法把radio控件完全隐藏起来只留效果?
HTML code

<html>
<head>
<title></title>
<script src="jquery-1.7.2.min.js" type="text/javascript"></script>

<style type="text/css">  
#radio1,#radio2,#radio3{width:50px; background-repeat:no-repeat;}
#radio1{ background-image:url("1.png");}
#radio1.a{ background-image:url("11.png");}

#radio2{ background-image:url("2.png");}
#radio2.a{ background-image:url("22.png");}

#radio3{ background-image:url("3.png");}
#radio3.a{ background-image:url("33.png");}}
</style>

<script type="text/javascript">
$(function(){
$("input[name=p];radio").click(function() {
  $("input[name=p];radio").removeClass("a");
  $(this).addClass("a");
  });
});
</script>

</head>

<body>
  <input type="radio" name="p" id="radio1" />  
  <input type="radio" name="p" id="radio2" />
  <input type="radio" name="p" id="radio3" />
</body>
</html> 



------解决方案--------------------
给他加个wrapper 
<div class="wrapper"><input...
...
$(".wrapper").css({"display":"hidden"});
------解决方案--------------------
简单,点完按钮后,隐藏。

JScript code
Ext.getCmp('myradio').setVisible(false);

------解决方案--------------------
JScript code
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js" type="text/javascript"></script>  

<style type="text/css">  
#radio1,#radio2,#radio3{width:50px;height:20px;float:left;}
#radio1{  background-color:#f5aece; }
#radio1.a{ background-color:red;}

#radio2{background-color:#aef5be;}
#radio2.a{ background-color:green;}

#radio3{ background-color:#aec6f5;}
#radio3.a{ background-color:blue;}
</style>

<script type="text/javascript">
    $(function () {
        //清空所有已选radio, 避免无法对应; 并隐藏
        $("#pVirtulRadios :radio").removeAttr("checked").hide();
        $("#pVirtulRadios label").click(function () {
            $("#pVirtulRadios label").removeClass("a");
            $(this).addClass("a");
        });
    });

    function test() {
        var $chkRadio = $("#pVirtulRadios :radio:checked");
        if ($chkRadio.length == 0) {
            alert("没有选中任何值.");
        } else {
            alert("您选中了: "+$chkRadio.val() );
        }
    }
</script>

</head>

<body>
  <p id="pVirtulRadios" style="width:100%;" >
    <label id="radio1" for="radio4" ></label>
    <label id="radio2" for="radio5" ></label>
    <label id="radio3" for="radio6" ></label>
    <input type="radio" name="p" id="radio4" value="第1个" />  
    <input type="radio" name="p" id="radio5" value="第2个"  />
    <input type="radio" name="p" id="radio6" value="第3个"  />
  </p>
  <br />
  <div style="width:100%;float:left;" >
    <input type="button" onclick="te