jq 二级筛选切换


		<style type="text/css">
			.content .miniNav{
				    position: relative;
				    width: 100%;
				    height: 120px;
				    border-bottom: 1px solid #e5e5e5;
				    background: transparent;
				    z-index: 10;
			}
			.box{
				height: 84px;
				margin-top: 18px;
				margin-bottom: 18px;
			}
			.box .ziliao,.box .ziliaoList{
				height: 42px;
			}
			.box .des{
				color: #aaa;
				font-weight: 600;
				width: 62px;
				display: inline-block;
				padding: 5px 6px;
				margin: 5px 22px;
			}
			.box a{
				cursor: pointer;
				display: inline-block;
				color: #333;
				text-decoration: none;
			}
			.ziliao,.ziliaoList,.fiveLine{
				font-size: 14px;
			}
			.box .item {
				padding: 5px 6px;
				margin: 5px 22px;
				display: inline-block;
				color: #333;
				text-decoration: none;
			}
			.box .item--active {
				border-radius: 2px;
				color: #fff !important;
				background: #fc2328;
				box-shadow: 2px 2px 5px rgba(0, 0, 0, .05);
			}
		</style>

		<div class="miniNav">
			<!-- 筛选 -->
			<div class="box">
				<div class="ziliao">
					<span class="des">全部资料</span>
				</div>
				<div class="ziliaoList">
					<span class="des fenlei">资料分类</span>
				</div>
				<div class="fiveLine"></div>
			</div>
		</div>
<script type="text/javascript">
			//获取地址栏url
			var URL = location.href
			$.ajax({
				url: 'http://www.xiaoma.com/channel_ajax.php?url=http://www.xiaoma.com/satpd/satyd/',
				type: 'post',
				data: {},
				dataType: 'json'
			}).then(function(res) {
				//把从json获取的数据赋值给空数组
				var str = ''
				var str2 = ''
				var str3 = ''
				var defaultThirdId = res.defaultThirdId
				var defaultFourId = res.defaultFourId
				var defaultFiveId = res.defaultFiveId
				//先判断该层是否有数据
				if(res.thirdData.length!=0){
				$.each(res.thirdData,function(index,element){
				     if (element.id==defaultThirdId) {
				     	 str +="<a class='item item--active'  href="+element['typedir']+">"+element['typename']+"</a>"
				     } else{
				     	 str +="<a class='item'  href="+element['typedir']+">"+element['typename']+"</a>"
				     }
				})
				}
				//先判断该层是否有数据
				if(res.fourData.length!=0){
				$.each(res.fourData,function(index,element){
					if (element.id==defaultFourId) {
						 str2 +="<a class='item item--active'  href="+element['typedir']+">"+element['typename']+"</a>"
					} else{
						 str2 +="<a class='item'  href="+element['typedir']+">"+element['typename']+"</a>"
					}
				})
				}
				if(res.fiveData.length!=0){
				$.each(res.fiveData,function(index,element){
						if (element.id==defaultFiveId) {
							 str3 +="<a class='item item--active'  href="+element['typedir']+">"+element['typename']+"</a>"
						} else{
							 str3 +="<a class='item'  href="+element['typedir']+">"+element['typename']+"</a>"
						}
				})
				}
				//遍历完成之后挂上去
				$('.ziliao').append(str)
				$('.ziliaoList').append(str2)
				$('.fiveLine').append(str3)
			}).fail(function() {
				console.log('获取数据失败');
			})
		</script>
		
posted @ 2019-11-04 11:15  Heson  阅读(294)  评论(0编辑  收藏  举报
Live2D