简要咨询咨询QQ网站导航网站搜索手机站点联系我们设为首页加入收藏 

单选按钮多选按钮用图片实现加样式

来源:易贤网   阅读:1366 次  日期:2016-06-14 09:46:56

温馨提示:易贤网小编为您整理了“单选按钮多选按钮用图片实现加样式”,方便广大网友查阅!

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

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>

更多信息请查看网页制作
点此处就本文及相关问题在本站进行非正式的简要咨询(便捷快速)】     【点此处查询各地各类考试咨询QQ号码及交流群
上一篇:如何在html中加载flash(2种实现方法)
下一篇:利用css生成精美细线table表格无需复杂style代码
易贤网手机网站地址:单选按钮多选按钮用图片实现加样式
由于各方面情况的不断调整与变化,易贤网提供的所有考试信息和咨询回复仅供参考,敬请考生以权威部门公布的正式信息和咨询为准!