Json string:
Copy codeThe Code is as follows: var mcode = {"minfo": [{"time": "-", "status": 2 },{ "time ": "-", "status": 1 },{ "time": "-", "status": 3 },{ "time ": "-", "status": 1 },{ "time": "-", "status": 1 },{ "time ": "-", "status": 1 },{ "time": "-", "status": 1 },{ "time ": "-", "status": 1}]};
Time indicates the time period. The status table can be used when the position 1 is used, the table 2 is expired, and the table 3 is selected as full.
The data values in the json string are traversed cyclically.
Copy codeThe Code is as follows:
For (var I in mcode. minfo ){
Mcode. minfo [I]. time + mcode. minfo [I]. status;
}
When the current time period is expired or is selected to be full, a message is displayed when you move the cursor over the current time period. move the cursor away to cancel the prompt.
The current time period is orange, which indicates you can select.
Copy codeThe Code is as follows:
$. 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 ("You selected:" + $ (this). text ());
});
}
});
Concatenate a string to construct an html structure.
Copy codeThe Code is as follows:
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> expired </label> ';
}
Else if (mcode. minfo [I]. status = 3 ){
Html + = '<label> selected </label> ';
}
If (mcode. minfo [I]. status! = 1 ){
Html + = '<em> </em> ';
}
Html + = "</span> ";
}
Css style:
Copy codeThe Code is as follows:
# Test {width: pixel PX; 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; border-style: solid; border-width: 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}
Instance:
Copy codeThe Code is as follows:
<! DOCTYPE html>
<Html>
<Head>
<Title> </title>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8">
<Script type = "text/javascript" src = "http://demo.jb51.net/jslib/jquery/jquery.js"> </script>
<Style type = "text/css">
* {Margin: 0px; padding: 0px ;}
# Test {width: pixel PX; 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; border-style: solid; border-width: 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 ",
"Status": 2
},
{
"Time ",
"Status": 1
},
{
"Time ",
"Status": 3
},
{
"Time ",
"Status": 1
},
{
"Time ",
"Status": 1
},
{
"Time ",
"Status": 1
},
{
"Time ",
"Status": 1
},
{
"Time ",
"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> expired </label> ';
}
Else if (mcode. minfo [I]. status = 3 ){
Html + = '<label> selected </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 ("You selected:" + $ (this). text ());
});
}
});
</Script>
</Body>
</Html>