国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > JavaScript > 正文

基于jquery的時間段實現代碼

2024-05-06 14:21:28
字體:
來源:轉載
供稿:網友
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);
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 博客| 蕲春县| 平谷区| 格尔木市| 通江县| 施秉县| 丹寨县| 土默特左旗| 富源县| 城市| 修水县| 镇雄县| 饶平县| 波密县| 宁强县| 韶山市| 古蔺县| 彭泽县| 吕梁市| 遵义县| 保山市| 法库县| 封开县| 吉林市| 县级市| 东平县| 鲁山县| 江门市| 子洲县| 澄江县| 十堰市| 日土县| 郎溪县| 绍兴市| 西乡县| 呼玛县| 来宾市| 抚宁县| 大埔区| 六枝特区| 阜平县|