前端html小课堂—单、复选按钮解析

今天分享下前端html小课堂—单、复选按钮解析,文中根据实例编码详细介绍,或许对大家的编程之路有着一定的参考空间与使用价值,需要的朋友接下来跟着云南仟龙Mark一起学习一下吧。 我以前看到有人问,如何添加单选按钮和多选按钮的样式以及如何使按钮变大?让我们分享一个我做的例子。

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 {

<p>http://www.qlyl1688.com</p>

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>

以上是云南仟龙Mark给大家介绍的所有内容,希望对大家有所帮助,如果大家有任何疑问请在脚本之家留言,如果你觉得本文对你有帮助,欢迎转载,烦请注明出处,谢谢!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值