1. 程式人生 > >jq點選lable自定義單選框變換樣式並且選中input

jq點選lable自定義單選框變換樣式並且選中input

<style>

input[type='radio'] {

display: none;

}

.ui-zidingyi {
    width: 20px;
    height: 20px;
    display: inline-block;
    background: url(../img/未選中-大.png) no-repeat;
    position: relative;
    top: 2px;
    left: 84px;
}

</style>

<div class="ui-dataLt">
                                    <label class="ui-zidingyi">
                                        <input name="vehicle" type="checkbox" />
                                    </label>             
  </div>

<scriput>

$(function() {
                $(".ui-zidingyi").toggle(function() {
                    $(this).css("background-image", "url(img/已選中-大.png)");
                    $(this).find("input").attr("checked","checked");
                    
                },function(){
                    $(this).css("background-image", "url(img/未選中-大.png)");
                    $(this).find("input").attr("checked",false);
                })
            });

</scriput>