左侧:菜单,给每个菜单设置id和onclick点击事件,onclick事件触发的函数假设写为display()
右侧:写个固定样式的div,id假设设置为board。
如果你的菜单内容在服务器
display()的实现如下
function display(){$.ajax({type: "POST",url: 菜单所请求的内容地址,data: this.id等等相关的请求标志,success: funtion(data){$('board').html(data)},//返回数据填充dataType: dataType})}
如果菜单内容写死在页面内
那么右侧:写和菜单数一样多的div,把所有的display属性设置为none
同时display()的实现如下
function display(){$('#'+$(this).attr('rel')).style.display='block'}
以上,伪代码,仅供参考
一般出现这种情况,往往是这个宽度的问题。宽度没有写死,正常的时候的一级菜单的宽度和hover状态下一级菜单的宽度不同,所以会掉下来。
下面有一个二级菜单的demo,可以对照着找一下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html charset=utf-08" />
<title>dropline-水平三级横向d出菜单</title>
<style type="text/css">
/* common styling */
.hd3_nav {font-family: arial, sans-serif width:749px height:30px position:relative margin:0 font-size:11px margin:0 background:#fff position:relative}
.hd3_nav ul {padding:0 margin:0 list-style-type: none}
.hd3_nav ul li {float:left border-left:1px solid #eee width:106px}
.hd3_nav ul li a, .hd3_nav ul li a:visited {display:block float:left width:101px text-decoration:none padding:0 0 0 5px height:30px line-height:30px color:#000 background:#c9c9a7 url(../../graphics/drop.gif) bottom right no-repeat}
.hd3_nav ul li ul {display: none}
/* specific to non IE browsers */
.hd3_nav ul li:hover a {color:#fff background:#b3ab79}
.hd3_nav ul li:hover ul {display:block position:absolute width:749px top:30px left:0 background:#b3ab79 color:#fff}
.hd3_nav ul li:hover ul.right_side li {float:right border:0 border-left:1px solid #eee}
.hd3_nav ul li:hover ul.left_side li {float:left border:0 border-left:1px solid #eee}
.hd3_nav ul li:hover ul li a.hide {background:#bd8d5e url(../../graphics/drop2.gif) bottom right no-repeat color:#fff}
.hd3_nav ul li:hover ul li:hover a.hide {background:#b3ab79 color:#fff}
.hd3_nav ul li:hover ul li ul {display: none}
.hd3_nav ul li:hover ul li a {display:block background:##b3ab79 color:#fff}
.hd3_nav ul li:hover ul li a:hover {background:#dfc184 color:#000}
.hd3_nav ul li:hover ul li:hover ul {display:block position:absolute left:0 top:30px color:#000 background:#dfc184}
.hd3_nav ul li:hover ul.right li {float:right}
.hd3_nav ul li:hover ul li:hover a.hide {background:#dfc184 color:#000}
</style>
</head>
<body>
<div class="hd3_nav">
<ul>
<li><a class="hide" href="../hd3_nav/index.html">第1个</a>
<ul>
<li><a href="../hd3_nav/zero_dollars.html" title="The zero dollar ads page">zero dollars</a></li>
<li><a href="../hd3_nav/embed.html" title="Wrapping text around images">wrapping text</a></li>
<li><a href="../hd3_nav/form.html" title="Styling forms">styled form</a></li>
<li><a href="../hd3_nav/nodots.html" title="Removing active/focus borders">active focus</a></li>
<li><a href="../hd3_nav/hover_click.html" title="Hover/click with no active/focus borders">HOVER/CLICK</a></li>
<li><a href="../hd3_nav/shadow_boxing.html" title="Multi-position drop shadow">shadow boxing</a></li>
<li><a href="../hd3_nav/old_master.html" title="Image Map for detailed information">image map</a></li>
</ul>
</li>
<li><a class="hide" href="index.html">第2个</a>
<ul>
<li><a href="spies.html" title="a coded list of spies">spies hd3_nav</a></li>
<li><a href="vertical.html" title="a horizontal vertical hd3_nav">vertical hd3_nav</a></li>
<li><a href="expand.html" title="an enlarging unordered list">enlarging list</a></li>
<li><a href="enlarge.html" title="an unordered list with link images">link images</a></li>
<li><a href="cross.html" title="non-rectangular links">non-rectangular</a></li>
<li><a href="jigsaw.html" title="jigsaw links">jigsaw links</a></li>
<li><a href="circles.html" title="circular links">circular links</a></li>
</ul>
</li>
<li><a class="hide" href="../layouts/index.html">第3个</a>
<ul>
<li><a href="../layouts/bodyfix.html" title="Cross browser fixed layout">Fixed 1</a></li>
<li><a href="../layouts/body2.html" title="Cross browser fixed layout">Fixed 2</a></li>
<li><a href="../layouts/body4.html" title="Cross browser fixed layout">Fixed 3</a></li>
<li><a href="../layouts/body5.html" title="Cross browser fixed layout">Fixed 4</a></li>
<li><a href="../layouts/minimum.html" title="A simple minimum width layout">minimum width</a></li>
</ul>
</li>
<li><a class="hide" href="../boxes/index.html">第4个</a>
<ul>
<li><a href="spies.html" title="a coded list of spies">spies hd3_nav</a></li>
<li><a href="vertical.html" title="a horizontal vertical hd3_nav">vertical hd3_nav</a></li>
<li><a href="expand.html" title="an enlarging unordered list">enlarging list</a></li>
<li><a href="enlarge.html" title="an unordered list with link images">link images</a></li>
<li><a href="cross.html" title="non-rectangular links">non-rectangular</a></li>
<li><a href="jigsaw.html" title="jigsaw links">jigsaw links</a></li>
<li><a href="circles.html" title="circular links">circular links</a></li>
</ul>
</li>
<li><a class="hide" href="../mozilla/index.html">第5个</a>
<ul>
<li><a href="../mozilla/dropdown.html" title="A drop down hd3_nav">drop down hd3_nav</a></li>
<li><a href="../mozilla/cascade.html" title="A cascading hd3_nav">cascading hd3_nav</a></li>
<li><a href="../mozilla/content.html" title="Using content:">content:</a></li>
<li><a href="../mozilla/moxbox.html" title=":hover applied to a div">mozzie box</a></li>
<li><a href="../mozilla/rainbow.html" title="I can build a rainbow">rainbow box</a></li>
<li><a href="../mozilla/snooker.html" title="Snooker cue">snooker cue</a></li>
<li><a href="../mozilla/target.html" title="Target Practise">target practise</a></li>
</ul>
</li>
<li><a class="hide" href="../ie/index.html">第6个</a>
<ul class="right_side">
<li><a href="../ie/exampleone.html" title="Example one">example one</a></li>
<li><a href="../ie/weft.html" title="Weft fonts">weft fonts</a></li>
<li><a href="../ie/exampletwo.html" title="Vertical align">vertical align</a></li>
</ul>
</li>
<li><a class="hide" href="../opacity/index.html">第6个</a>
<ul class="right_side">
<li><a href="../opacity/colours.html" title="colour wheel">opaque colours</a></li>
<li><a href="../opacity/picturehd3_nav.html" title="a hd3_nav using opacity">opaque hd3_nav</a></li>
<li><a href="../opacity/png.html" title="partial opacity">partial opacity</a></li>
<li><a href="../opacity/png2.html" title="partial opacity II">partial opacity II</a></li>
<li><a href="../hd3_nav/hover_click.html" title="Hover/click with no active/focus borders">HOVER/CLICK</a></li>
</ul>
</li>
</ul>
</div>
</body>
</html>
要实现这个功能其实非常简单,下面的思路希望对你有用。步骤如下:一般WEB开发把页面分成3个模块:header.tpl content.tpl footer.tpl。head和footer一般都是固定不变的,唯一变化的部分是content。你说的菜单应该是header部分的导航部分。例如主页的代码可以这样写:
<html>
<head></head>
<body>
{include file="head.tpl"} <!-- 导航部分 -->
{include file="content.tpl"} <!-- 变化内容 -->
{include file="footer.tpl"} <!-- 版权内容 -->
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)