0
点赞
收藏
分享

微信扫一扫

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

林肯公园_97cc 2022-01-26 阅读 44

今天分享下前端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 条评论