前几天我经理突然跟我说,能不能做一个开关按钮,需要过滤的一个标识。说实话,一个做后端我是懵逼状态的。

不过网上资料很多,查了一遭,发现一个不错的哥们给出的案例,模仿一下成功实现,下面就自己总结一下:

实现的效果如上,个人觉得丑爆了。

下面是实现过程:

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获取按钮状态。的更多相关文章

  1. 关于jQuery获取checkbox状态的问题

    这位大神概括的很好 http://www.cnblogs.com/wangkongming/p/4002710.html

  2. jquery获取checkbox状态

    $("#id").is(":checked"); 返回true false

  3. jquery获取当前按钮、截取字符串、字符串拼接、动态循环添加元素

    截取字符串:字符串拼接:动态循环添加元素:获取当前按钮: {data : null, render: function(data, type, row ) { var loginName = $(&q ...

  4. jquery mobile 按钮部件(包含图标的使用)

    参考网址:http://api.jquerymobile.com/1.3/button/ 注:按钮的三种写法 <a href="#" class="ui-btn u ...

  5. jquery倒计时按钮常用于验证码倒计时

    <!doctype html><html><head> <meta charset="utf-8"> <title>jq ...

  6. 主攻ASP.NET MVC4.0之重生:Jquery Mobile 按钮+对话框使用

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  7. jquery带按钮的图片切换效果

    <!doctype html> <html> <head> <meta charset="gb2312"> <title> ...

  8. Android自定义工具类获取按钮并绑定事件(利用暴力反射和注解)

    Android中为按钮绑定事件的有几种常见方式,你可以在布局文件中为按钮设置id,然后在MainActivity中通过findViewById方法获取按钮对象实例,再通过setOnClickListe ...

  9. (三)Jquery Mobile按钮详细讲解

    Jquery Mobile按钮详细讲解 一.JM按钮说明 按钮如下图所示           1.HTML5中的button      效果:      2. JM中的普通button        ...

随机推荐

  1. 洛谷 题解 UVA1626 【括号序列 Brackets sequence】

    看还没有人发记搜的题解,赶紧来水发一篇 我们定义dp[i][j]为区间i~j内最少添加几个括号才能把这个串变成正规括号序列. 考虑四种情况 i>j不存在这种子串,返回0 i==j子串长度为1无论 ...

  2. Reactor系列(九)collect集合

    #java#reactor#collect#collectMap#collectList# 集合 视频讲解: https://www.bilibili.com/video/av79860614/ Fl ...

  3. There are no packages available

    { "bootstrapped": true, "channels": [ "https://raw.githubusercontent.com/Ja ...

  4. lab3:系统调用

    jos系统调用函数链 记录自己对jos系统调用实现的理解. 用户程序访问系统服务的方法 用户使用系统服务的方式大概分为如下几种: (1)用户程序---->库函数----->系统调用---- ...

  5. JVM学习(一)Java虚拟机运行时数据区域

    一.Java内存区域 1.运行时数据区域 根据<Java 虚拟机规范(Java SE 7 版)>规定,Java 虚拟机所管理的内存包括以下几个运行时数据区域: 1.1 程序计数器 程序计数 ...

  6. php中连接tcp服务的三种方式

    首先需要现有一个 tcp 服务,我们使用 php中的 socket 系列函数实现 <?php //创建socket套接字 $socket = socket_create(AF_INET, SOC ...

  7. python爬取网页数据并存储到mysql数据库

    #python 3.5 from urllib.request import urlopen from urllib.request import urlretrieve from bs4 impor ...

  8. Python 【格式化字符串】

    print('血量:'+str(player_life)+' 攻击:'+str(player_attack)) 第一种格式化字符串 print('血量:%s 攻击:%s' % (player_life ...

  9. android中sqlite数据库的基本使用和添加多张表

    看了很多关于android使用sqlite数据库的文章,很多都是介绍了数据库的建立和表的建立,而表通常都是只建立一张,而实际情况我们用到的表可能不止一张,那这种情况下我们又该怎么办呢,好了,下面我教大 ...

  10. springcloud eureka注册中心分布式配置

    最近在学习springcloud,做下笔记以及记下遇到的坑. 1.建立maven工程,结构很简单,一个启动类和一个配置文件,结构如下图所示 2.启动类代码如下,需要添加注册中心注解:EnableEur ...