jQuery 菜单项切换

摘要:
//注意保留timeID,否则无法清除//请注意,timeOut的第一个参数应写入行timeOutID=setTimeout(function(){me.addClass('tableIn');varlis=$('.menuli');lis.each(function(index,value){varcontentDiv=$('container').childres('div').eq(index);//应将其转换为元素并等待,如果(me.get(0)!=value){$.removeClass;}否则{if{contentDiv.load;}el-seif{//如果这里没有JSP,则不会编写JSP。加载方法}elseif{}});})})还使用标签1标签2标签3内容1内容2内容3˃class=“load_tableIn”˃加载完整页面加载JSP的一部分加载所有JSP
<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			ul {
				list-style: none;
				padding: 0;
				margin: 0;
			}
			
			.menu li {
				background: gray;
				text-align: center;
				line-height: 30px;
				padding: 5px 10px;
				 50px;
				color: white;
				float: left;
				margin-right: 2px;
			}
			
			.menu li.tableIn {
				background-color: #003580;
				border: 1px solid #003580;
			}
			
			.menu:after {
				content: '';
				display: block;
				clear: both;
				overflow: hidden;
			}
			
			.content {
				display: block;
				background: #003580;
				 300px;
				height: 300px;
				color: white;
				padding: 5px 10px;
			}
			
			.defaut {
				display: none;
			}
			
			#load_menu li {
				float: left;
				padding: 3px 5px;
				color: blue;
				height: 30px;
				line-height: 30px;
				position: relative;
				z-index: 99;
			}
			
			#load_menu:after{
				content: '';
				display: block;
				clear: both;
				overflow: hidden;
			}
			
			#load_menu .load_tableIn {
				background: lightgray;
				border: 1px solid black;
				border-bottom: 0;
			}
			
			#load_content {
				 400px;
				height: 300px;
				background: lightgray;
				clear: both;
				border: solid 1px black;
				position: relative;
				top: -2px;
				padding-top: 30px;
			}
		</style>
		<script src="http://t.zoukankan.com/jquery-2.2.4.min.js"></script>
		<script>
			$(window).load(function() {
				var timeOutID = null;
				$('.menu li').hover(function() {
					var me = $(this);
					//防止快速点击的方法。。。
					//注意保留timeID,不然无法清除
					//注意timeOut的第一个参数要写在本行
					timeOutID = setTimeout(function() {
						me.addClass('tableIn');
						var lis = $('.menu li');

						lis.each(function(index, value) {
							var contentDiv = $('.container').children('div').eq(index);
							//要转换为元素再等
							if (me.get(0) != value) {
								$(value).removeClass('tableIn');
								contentDiv.removeClass('content');
								contentDiv.addClass('defaut');
							} else {
								contentDiv.removeClass('defaut');
								contentDiv.addClass('content');
							}
						});
					}, 300);
				}, function() {
					clearTimeout(timeOutID);
				})
				//默认加载本地页面
				$('#load_content .real_content').load("testload.html");

				$('#load_menu li').on('click', function() {
					var me = $(this);
					//注意timeOut的第一个参数要写在本行
					me.addClass('load_tableIn');
					var lis = $('#load_menu li');

					lis.each(function(index, value) {
						var contentDiv = $('#load_content .real_content');
						//要转换为元素再等
						if (me.get(0) != value) {
							$(value).removeClass('load_tableIn');
						} else {
							if (index == 0) {
								contentDiv.load("testload.html");
							} else if (index == 1) {
								//这里没JSP,就没写了,也是用load方法
							} else if (index == 2) {

							}
						}
					});
				})
			});
		</script>
	</head>

	<body>
		<div class="container">
			<ul class="menu">
				<li class="tableIn">标签1</li>
				<li>标签2</li>
				<li>标签3</li>
			</ul>
			<div class="content">内容1</div>
			<div class="defaut">内容2</div>
			<div class="defaut">内容3</div>

		</div>
		<br />
		<br/>
		<ul id="load_menu">
			<li class="load_tableIn">加载完整页面</li>
			<li>加载部分JSP</li>
			<li>加载全部JSP</li>
		</ul>
		<div id="load_content">
			<div class="real_content"></div>
		</div>
	</body>

</html>

  

免责声明:文章转载自《jQuery 菜单项切换》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Chrome打开标签页预览Adobe/Flash Media Server 5.0 linux 64位系统下的安装下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Android—简单的仿QQ聊天界面

最近仿照QQ聊天做了一个类似界面,先看下界面组成(画面不太美凑合凑合呗,,,,):     其中聊天背景可以是一个LinearLayout或者RelativeLayout里面存放的是ListView(将ListView的分割线设置成透明:android:divider="#0000"否则聊天界面会显示出分割线,,,想想都屌,,,)    于是,我要上主界...

Jquery中用offset().top和offsetTop的比较

今天,想测试一个div与顶部的距离,用的是.offsetTop,但是offsetTop获得的值,怎么都打印不出来。折腾了半天,打印的结果都是undefined,虽然网上很多资料都说返回的是数值。虽然这个函数永不了,但是黄显钦找到了一个可以替代offsetTop的函数。那就是jquery的offset().top   我们先来了解一下,什么是offset(...

CSS伪元素before和after

今天发现很多国外的网站和框架设计都用到了before和after,之前使用的比较少,今天试了下觉得还是很有意思的~ 说明 1. :before 和 :after将在内容元素的前后插入额外的元素;:before将会在内容之前“添加”一个元素而:after将会在内容后“添加”一个元素。在它们之中添加内容我们可以使用content属性。 2. :before 和...

JQuery的AJAX

定义和用法 ajax() 方法通过 HTTP 请求加载远程数据。 该方法是 jQuery 底层 AJAX 实现。简单易用的高层实现见 $.get, $.post 等。$.ajax() 返回其创建的 XMLHttpRequest 对象。大多数情况下你无需直接操作该函数,除非你需要操作不常用的选项,以获得更多的灵活性。 最简单的情况下,$.ajax() 可以不...

移动端-手机端-日历选择控件(支持Zepto和JQuery)

一. 效果图 二. 功能说明   1. 支持切换年份,月份。   2. 支持点击选中日期,也可以点击确定选择日期。 三. 使用方法   1. 添加Input   在你的页面中添加Input输入框。可以再html里,也可以JS动态加载。   我这里使用的时Input-group形式的输入框,是JS加载的。   一般使用的话,直接写个input输入框就行。...

html使用代码大全

<DIV style="FONT-SIZE: 9pt">1)贴图:<img src="http://t.zoukankan.com/图片地址">1)首行缩进2格:<p style="TEXT-INDENT: 2em">html使用代码大全</p> 2)加入连接:<a href="http://t.zou...