CSS实现按钮YES-NO按钮+Jquery获取按钮状态。
前几天我经理突然跟我说,能不能做一个开关按钮,需要过滤的一个标识。说实话,一个做后端我是懵逼状态的。
不过网上资料很多,查了一遭,发现一个不错的哥们给出的案例,模仿一下成功实现,下面就自己总结一下:


实现的效果如上,个人觉得丑爆了。
下面是实现过程:
HTML部分代码:
<div class="testswitch">
<input class="testswitch-checkbox" id="onoffswitch" type="checkbox">
<label for="onoffswitch" class="testswitch-label">
<span class="testswitch-inner" data-on="YES" data-off="NO"></span>
<span class="testswitch-switch"></span>
</label>
</div>
CSS部分代码:
.testswitch {
position: relative;
float: left;
width: 45px;
margin: 0;
font-size: 0.6em;
}
.testswitch-checkbox {
display: none;
}
.testswitch-label {
display: block;
overflow: hidden;
cursor: pointer;
border-radius: 20px;
}
.testswitch-inner {
display: block;
width: 200%;
margin-left: -100%;
transition: margin 0.3s ease-in 0s;
text-align: left;
}
.testswitch-inner::before,
.testswitch-inner::after {
display: block;
float: right;
width: 50%;
height: 20px;
padding: 0;
line-height: 1.8em;
font-size: 8px;
color: white;
font-family: Trebuchet, Arial, sans-serif;
font-weight: bold;
box-sizing: border-box;
}
.testswitch-inner::after {
content: attr(data-on);
padding-left: 10px;
background-color: #FFAB47;
color: #FFFFFF;
}
.testswitch-inner::before {
content: attr(data-off);
padding-right: 10px;
background-color: #3F9FE8;
color: white;
text-align: right;
}
.testswitch-switch {
position: absolute;
display: block;
width: 12px;
height: 12px;
margin: 4px;
background: #FFFFFF;
bottom: 5px;
border-radius: 20px;
transition: all 0.3s ease-in 0s;
text-align: right;
}
.testswitch-checkbox:checked+.testswitch-label .testswitch-inner {
margin-left: 0;
}
.testswitch-checkbox:checked+.testswitch-label .testswitch-switch {
right: 0px;
}
Jquery部分代码:
referrer="NO";
$(document).ready(function () {
$("#onoffswitch").on("click",function () {
clickSwitch();
});
var clickSwitch=function () {
if($("#onoffswitch").is(":checked")){
console.log("YES");
referrer="YES";
$('.sp-start').css('display','none');
$('.sp-close').css('display','block');
}else {
console.log("NO");
referrer="NO";
$('.sp-close').css('display','none');
$('.sp-start').css('display','block');
}
}
});
CSS实现按钮YES-NO按钮+Jquery获取按钮状态。的更多相关文章
- 关于jQuery获取checkbox状态的问题
这位大神概括的很好 http://www.cnblogs.com/wangkongming/p/4002710.html
- jquery获取checkbox状态
$("#id").is(":checked"); 返回true false
- jquery获取当前按钮、截取字符串、字符串拼接、动态循环添加元素
截取字符串:字符串拼接:动态循环添加元素:获取当前按钮: {data : null, render: function(data, type, row ) { var loginName = $(&q ...
- jquery mobile 按钮部件(包含图标的使用)
参考网址:http://api.jquerymobile.com/1.3/button/ 注:按钮的三种写法 <a href="#" class="ui-btn u ...
- jquery倒计时按钮常用于验证码倒计时
<!doctype html><html><head> <meta charset="utf-8"> <title>jq ...
- 主攻ASP.NET MVC4.0之重生:Jquery Mobile 按钮+对话框使用
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- jquery带按钮的图片切换效果
<!doctype html> <html> <head> <meta charset="gb2312"> <title> ...
- Android自定义工具类获取按钮并绑定事件(利用暴力反射和注解)
Android中为按钮绑定事件的有几种常见方式,你可以在布局文件中为按钮设置id,然后在MainActivity中通过findViewById方法获取按钮对象实例,再通过setOnClickListe ...
- (三)Jquery Mobile按钮详细讲解
Jquery Mobile按钮详细讲解 一.JM按钮说明 按钮如下图所示 1.HTML5中的button 效果: 2. JM中的普通button ...
随机推荐
- MapReduce 框架原理
1. Hadoop 序列化 1.1 自定义Bean对象实现序列化接口 必须实现 Writable 接口: 反序列化时,需要反射调用空参构造函数,所以必须有空参构造: 重写序列化方法: 重写反序列化方法 ...
- 西安区域赛 D.Miku and Generals 二分图+背包
Miku and Generals Describe "Miku is matchless in the world!" As everyone knows, Nakano Mik ...
- PHP学习之PHP的语法糖
PHP的语法糖 计算机语言中添加的某种语法,这种语法对语言的功能并没有影响,但是更方便程序员使用. 常见的PHP的语法糖 echo(),print(),die(),isset(),unset(),i ...
- python 字典所有操作
# 字典的创建# dict1 = {}# print(type(dict1))## dict2 = {# 'name':'汪峰',# 'sex':'男',# 'hiredate':'1997-10-2 ...
- 【leetcode】287. 寻找重复数
题目链接:传送门 题目描述: 给定一个数组 nums 包含 n + 1 个整数,每个整数在 1 到 n 之间,包括 1 和 n.现在假设数组中存在一个重复的数字,找到该重复的数字. 注意 不能修改数组 ...
- 并不对劲的CF1245E&F:Cleaning Ladders
CF1245 E. Hyakugoku and Ladders 题目大意 有一个10 \(\times\) 10的网格,你要按这样的路径行走: 网格中有一些单向传送门,每个传送门连接的两个格子在同一列 ...
- ubuntu中安装字体雅黑和consolas
Ubuntu的群体里偏向使用雅黑,我目前用的YaHei.Consolas 1.11 版本 (雅黑-Consolas的混合体) http://www.netmako.com/RobertLee/YaHe ...
- ASR性能测试方案--详细见云盘
目录: 1. 什么是WER 2. WER计算原理 3. WER测试设计方案 4. 当前业界识别水平 1. 什么是WER 在语音识别(Automatic Speech Recognition, ASR) ...
- Python下载安装及验证
目录: 一.Python介绍 二.python安装及验证 一.Python介绍 Python是著名的“龟叔”Guido van Rossum在1989年圣诞节期间,为了打发无聊的圣诞节而编写的一个 ...
- Image Processing and Computer Vision_Review:A survey of recent advances in visual feature detection(Author's Accepted Manuscript)——2014.08
翻译 一项关于视觉特征检测的最新进展概述(作者已被接受的手稿) 和A survey of recent advances in visual feature detection——2014.08内容相 ...