单选按钮多选按钮用图片实现加样式
2016-06-14来源:易贤网

之前一直看到有人在问,单选按钮和多选按钮怎么加样式、怎么把按钮变大?下面把我做的一个例子分享出来。

1.首先把按钮做成图片

2.html页面

代码如下:

<!doctype html>

<html>

<head>

<meta http-equiv=content-type content=text/html; charset=utf-8 />

<script type=text/javascript src=jquery-1.10.2.min.js></script>

<script type=text/javascript>

$(function(){

$(input[type='checkbox']).click(function(){

if($(this).is(':checked')){

$(this).attr(checked,checked);

$(this).parent().removeclass(c_off).addclass(c_on);

}else{

$(this).removeattr(checked);

$(this).parent().removeclass(c_on).addclass( c_off);

}

});

$(input[type='radio']).click(function(){

$(input[type='radio']).removeattr(checked);

$(this).attr(checked,checked);

$(this).parent().removeclass(r_off).addclass(r_on).siblings().removeclass(r_on).addclass(r_off);

});

});

</script>

</head>

<style>

/* 多选/单选 */

label {

display: block;

cursor: pointer;

line-height: 26px;

margin-bottom: 20px;

width: 26px;

height: 26px;

line-height: 26px;

float: left;

margin-top: 6px;

}

.radios {

padding-top: 18px;

border-top: 1px solid #049cdb;

}

.label_check input, .label_radio input {

margin-right: 5px;

}

.lblby .label_check, .lblby .label_radio {

margin-right: 8px;

}

.lblby .label_radio, .lblby .label_check {

background: url(../images/jxc_btn.png) no-repeat;

}

.lblby .label_check {

background-position: 0 0px

}

.lblby label.c_on {

background-position: 0 -26px;

}

.lblby .label_radio {

background-position: 0 -52px;

}

.lblby label.r_on {

background-position: 0 -78px;

}

.lblby .label_check input, .lblby .label_radio input {

position: absolute;

left: -9999px;

}

</style>

<body class=lblby>

<label for=checkbox-01 class=label_check c_on>

<input type=checkbox checked=checked value=1 id=checkbox-01 name=sample-checkbox-01 />

checkbox1 </label>

<label for=checkbox-02 class=label_check>

<input type=checkbox value=1 id=checkbox-02 name=sample-checkbox-02 />

checkbox2</label>

<label for=radio-01 class=label_radio r_on>

<input type=radio value=1 checked=checked id=radio-01 name=sample-radio />

radio1 </label>

<label for=radio-02 class=label_radio r_off>

<input type=radio value=1 id=radio-02 name=sample-radio />

radio2 </label>

<label for=radio-03 class=label_radio r_off>

<input type=radio value=1 id=radio-03 name=sample-radio />

radio3 </label>

</body>

</html>

2026公务员·事业单位培训课程试听报名

  • 报班类型
  • 姓名
  • 手机号
  • 验证码
推荐信息