jquery 时间段

简介: 首先,看下效果图: json字符串:var mcode={"minfo":[{"time":"9:00-10:00","status":2},{"time":"10:00-11:00","status":1},{"time":"11:00-12:00","status":3},{"time":"1...

首先,看下效果图:


json字符串:
var mcode={"minfo":[{"time":"9:00-10:00","status":2},{"time":"10:00-11:00","status":1},{"time":"11:00-12:00","status":3},{"time":"13:00-14:00","status":1},{"time":"14:00-15:00","status":1},{"time":"15:00-16:00","status":1},{"time":"16:00-17:00","status":1},{"time":"17:00-18:00","status":1}]};
其中time代表时间段,status当职位1时代表可以使用,2时代表已过期,3时代表已选满。
通过循环遍历json字符串中的数据值。

for(var i in mcode.minfo){
       mcode.minfo[i].time + mcode.minfo[i].status;
}


当前时间段为已过期或以选满时,鼠标移动到其当前时间段上时提示相应信息,鼠标移开取消提示。
当前时间段为橘黄色代表可以选择。

$.each($("#test span"),function(k,v){
     if($(this).hasClass("unspan1")||$(this).hasClass("unspan2")){
          $(this).hover(function(){
               $(this).find("label").css({"display":"block"});
               $(this).find("em").css({"display":"block"});  
          }, function(){
               $(this).find("label").css({"display":"none"});
               $(this).find("em").css({"display":"none"}); 
          }); 
     }
      else{
          $(this).click(function(){
            $("#result").empty().html("您选择了:"+$(this).text());
          });
      }
  });

 

拼接字符串,构建html结构。

for(var i in mcode.minfo){
    if(mcode.minfo[i].status===2){
        html+='<span class="unspan1 ';
    }
    else if(mcode.minfo[i].status===3){
         html+='<span class="unspan2 ';
    }
    else{
         html+='<span class=" ';
    }
    if((i+1)%3===0){
         html+='" >';
    }
    else{
         html+='mspan" >';   
    }
    html+=mcode.minfo[i].time;
         if(mcode.minfo[i].status===2){
              html+='<label>已过期</label>';
         }
         else if(mcode.minfo[i].status===3){
              html+='<label>已选满</label>';
         }
         if(mcode.minfo[i].status!==1){
              html+='<em></em>';
         }
    html+="</span>";
 }

 

css样式:

#test{ width: 430px; padding: 35px; border: 1px solid #666666;overflow: hidden; margin: 100px auto 0px;}
#test span{display:block; background: #FF6600; width:130px; height: 30px; line-height: 30px; text-align: center; float:left; 
_display
:inline; position:relative; margin-bottom: 15px; cursor: pointer;} #test .mspan{margin-right: 20px;} #test .unspan1{background: #D2E0E6; cursor:default} #test .unspan2{background: #ffcaca; cursor: default;} #test label{position: absolute; left:25px; top:-18px; width: 60px; line-height: 20px; background: #F3F3F3;
padding
:1px 10px; border:1px solid #CCCCCC;display: none;} #test em{display: block;border-color: #F3F3F3 transparent transparent transparent;border-style: solid;border-width: 6px 6px 6px 6px; padding: 0;width: 0;height: 0; font-size: 0;line-height: 0; position: absolute;left:58px; top:5px;display:none; _border-top-color: #F3F3F3;_border-bottom-color: #F3F3F3; _filter: chroma( color = #F3F3F3); } #result{ margin: 10px auto 0px; text-align: center}



实例:

<!DOCTYPE html> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript" src="http://files.cnblogs.com/kuikui/jquery.js"></script> <style type="text/css"> *{margin:0px;padding: 0px;} #test{ width: 430px; padding: 35px; border: 1px solid #666666;overflow: hidden; margin: 100px auto 0px;} #test span{display:block; background: #FF6600; width:130px; height: 30px; line-height: 30px; text-align: center; float:left; _display:inline; position:relative; margin-bottom: 15px; cursor: pointer;} #test .mspan{margin-right: 20px;} #test .unspan1{background: #D2E0E6; cursor:default} #test .unspan2{background: #ffcaca; cursor: default;} #test label{position: absolute; left:25px; top:-18px; width: 60px; line-height: 20px; background: #F3F3F3; padding:1px 10px; border:1px solid #CCCCCC;display: none;} #test em{display: block;border-color: #F3F3F3 transparent transparent transparent;border-style: solid;border-width: 6px 6px 6px 6px; padding: 0;width: 0;height: 0; font-size: 0;line-height: 0; position: absolute;left:58px; top:5px;display:none; _border-top-color: #F3F3F3;_border-bottom-color: #F3F3F3; _filter: chroma( color = #F3F3F3); } #result{ margin: 10px auto 0px; text-align: center} </style> </head> <body> <div id="test"> </div> <div id="result"></div> <script type="text/javascript"> var mcode = { "minfo": [ { "time": "9:00-10:00", "status": 2 }, { "time": "10:00-11:00", "status": 1 }, { "time": "11:00-12:00", "status": 3 }, { "time": "13:00-14:00", "status": 1 }, { "time": "14:00-15:00", "status": 1 }, { "time": "15:00-16:00", "status": 1 }, { "time": "16:00-17:00", "status": 1 }, { "time": "17:00-18:00", "status": 1 } ] }; var html = ''; for(var i in mcode.minfo){ if(mcode.minfo[i].status===2){ html+='<span class="unspan1 '; } else if(mcode.minfo[i].status===3){ html+='<span class="unspan2 '; } else{ html+='<span class=" '; } if((i+1)%3===0){ html+='" >'; } else{ html+='mspan" >'; } html+=mcode.minfo[i].time; if(mcode.minfo[i].status===2){ html+='<label>已过期</label>'; } else if(mcode.minfo[i].status===3){ html+='<label>已选满</label>'; } if(mcode.minfo[i].status!==1){ html+='<em></em>'; } html+="</span>"; } $("#test").empty().html(html); $.each($("#test span"),function(k,v){ if($(this).hasClass("unspan1")||$(this).hasClass("unspan2")){ $(this).hover(function(){ $(this).find("label").css({"display":"block"}); $(this).find("em").css({"display":"block"}); }, function(){ $(this).find("label").css({"display":"none"}); $(this).find("em").css({"display":"none"}); }); } else{ $(this).click(function(){ $("#result").empty().html("您选择了:"+$(this).text()); }); } }); </script> </body> </html>

目录
相关文章
|
存储 网络安全 网络架构
网络技术基础(5)——VRP和telnet
VRP(Versatile Routing Platform)是其数据通信产品的操作系统,支持路由器和交换机的高效运行,提供统一用户界面和控制平面功能。VRP通过组件化结构实现功能裁剪和扩展。设备初始化时,BootROM先启动,然后运行系统软件,从默认路径读取配置文件。管理设备可通过命令行或Web网管,命令行包括用户界面和级别控制,提供权限管理。文件系统管理涉及存储设备如SDRAM、Flash、NVRAM等。用户可使用 PuTTY 工具通过Console口本地登录,或通过SSH远程登录。VRP命令行具有编辑和在线帮助功能,提供undo命令恢复默认设置。
|
Cloud Native Linux 虚拟化
【云原生】Docker容器资源限制(CPU/内存/磁盘)
【云原生】Docker容器资源限制(CPU/内存/磁盘)
3492 0
lyL
|
12月前
|
Kubernetes NoSQL 应用服务中间件
物理部署图
物理部署图描述系统运行时的硬件配置与软件部署结构,展现节点、构件、物件及连接关系,帮助开发与运维人员理解分布式系统的部署架构与网络通信。
lyL
472 1
 物理部署图
|
12月前
|
机器学习/深度学习 人工智能 数据可视化
构建AI智能体:六十四、模型拟合的平衡艺术:深入理解欠拟合与过拟合
机器学习模型训练中存在欠拟合和过拟合两大核心问题。欠拟合指模型过于简单无法捕捉数据规律,表现为训练和测试误差均高;过拟合则是模型过于复杂导致记忆噪声而非规律,表现为训练误差低但测试误差高。解决欠拟合需增加模型复杂度(如多项式回归、决策树)或改进特征工程;解决过拟合则需限制复杂度(如降低树深度)、增加正则化或使用集成方法。MSE是关键的评估指标,良好拟合表现为训练集和测试集MSE均适中且接近。掌握这一平衡艺术是构建泛化能力强、稳健模型的关键。
1577 16
|
11月前
|
存储 人工智能 运维
炎鹊AI:让行业AI能力从“实验室”走向“生产力”的平民化革命
炎鹊AI推出Nexus Agent v1.0架构,以“垂直场景原生+低代码工具链+Agent化部署”重构AI落地路径。通过领域知识蒸馏、可视化编排与轻量化推理,实现AI应用从“专家驱动”到“业务自主”的跨越,降低技术门槛70%,缩短周期至小时级,赋能金融、医疗、制造等21大行业,推动AI真正走向平民化与普惠化。
471 3
|
12月前
|
机器人 Java API
钉钉通知
创建钉钉机器人并设置告警群,通过Webhook获取API地址。使用PostMan测试文本、@指定人及卡片消息发送。编写Java代码调用官方SDK实现消息推送,封装工具类并与Nacos配置中心集成,实现异常日志等场景下的实时告警通知,确保问题及时处理。
|
12月前
|
人工智能 自然语言处理 机器人
适合电商的智能客服系统推荐(2025年12月更新)
瓴羊Quick Service是阿里云旗下智能客服产品,深度整合电商交易链路,支持全渠道协同与大模型应用,具备高并发稳定性,助力中大型电商实现服务智能化与业务增长。
|
12月前
|
消息中间件 Ubuntu 中间件
Linux网络中间件入门指南(从零开始搭建高效网络通信架构)
本教程来源:https://www.vps5.cn/带你入门Linux网络中间件,介绍其在分布式系统中的核心作用。通过Ubuntu部署RabbitMQ实例,学习消息队列、服务代理等常见类型的应用与选型建议,助你提升系统通信效率与可靠性。
|
JSON 安全 算法
从0到1掌握1688API:商品详情获取技巧与避坑指南
1688商品详情API通过商品ID获取商品标题、价格库存、图片视频、SKU等结构化数据,支持字段定制与批发价查询,适用于电商整合与竞品分析。采用RESTful+JSON,需AppKey/Secret签名认证,保障数据实时安全。
|
传感器 人工智能 安全
物联网
万物互联,智启未来。物联网通过连接人、物、环境,重塑生活、城市与产业。从智能家居到智慧城市,从工业互联网到精准农业,数据驱动智能化变革。融合AI、5G等技术,构建高效、安全、可持续的智能世界,开启人类社会新篇章。(238字)