jquery+json实现动态商品内容展示的方法
本文实例讲述了jquery+json实现动态商品内容展示的方法。分享给大家供大家参考,具体如下:
<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml"xml:lang="zh"lang="zh"dir="ltr">
<head>
<metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/>
<mce:scripttype="text/javascript"src="jquery-1.4.4.min.js"mce_src="jquery-1.4.4.min.js"></mce:script>
<title>Example|xHTML1.0</title>
</head>
<mce:style><!--
div{width:50px;height:50px;float:left;margin:10px;text-align:center;}
.a{font-size:50px;float:left;cursor:pointer;}
.b{font-size:50px;background-color:yellow;float:left;cursor:pointer;}
.border{border:2pxsolid;}
.bb{}
--></mce:style><stylemce_bogus="1">div{width:50px;height:50px;float:left;margin:10px;text-align:center;}
.a{font-size:50px;float:left;cursor:pointer;}
.b{font-size:50px;background-color:yellow;float:left;cursor:pointer;}
.border{border:2pxsolid;}
.bb{}</style>
<mce:scripttype="text/javascript"><!--
$(function(){
var_json={"red":{"small":"10","middle":"15","large":"20","max_large":"25"},"blue":{"small":"33","middle":"35","large":"9","max_large":"30"},"green":{"small":"34","middle":"30","large":"19","max_large":"3"},"orange":{"small":"9","middle":"15","large":"29","max_large":"18"}};
var_color_value;
var_size_value;
var_store_value;
$("#select_colordiv").click(function(){
$("#select_colordiv").attr("class","/bb");
$(this).attr("class","border");
_color_value=$(this).attr("date-value");
change_span_value()
});
$("#select_sizediv").click(function(){
$("#select_sizediv").attr("class","a");
$(this).attr("class","b");
_size_value=$(this).attr("date-value");
change_span_value()
});
functionchange_span_value(){
var_value=_json[_color_value][_size_value];
if(_value!=undefined){
$("#span_store").text(_value+"件");
}
}
});
//--></mce:script>
<body>
<divstyle="width:100%;margin:10px;"id="select_color">
<divstyle="background-color:red;cursor:pointer;"mce_style="background-color:red;cursor:pointer;"date-value="red">Red</div>
<divstyle="background-color:blue;cursor:pointer;"mce_style="background-color:blue;cursor:pointer;"date-value="blue">Blue</div>
<divstyle="background-color:green;cursor:pointer;"mce_style="background-color:green;cursor:pointer;"date-value="green">Green</div>
<divstyle="background-color:orange;cursor:pointer;"mce_style="background-color:orange;cursor:pointer;"date-value="orange">Orange</div>
</div>
<divstyle="width:100%;margin:10px;"id="select_size">
<divclass="a"date-value="small">S</div>
<divclass="b"date-value="middle">M</div>
<divclass="a"date-value="large">L</div>
<divclass="a"date-value="max_large">XL</div>
</div>
<divstyle="width:100%;margin:10px;text-align:left;"id="select_store">
库存:(<spanid="span_store">1000件</span>)
</div>
<divstyle="border:2pxsolid;width:100px;height:100px;background-color:gray"></div>
</body>
</html>
更多关于jQuery操作json相关内容感兴趣的读者可查看本站专题:《jQuery操作json数据技巧汇总》
希望本文所述对大家jQuery程序设计有所帮助。