当前位置:编程学习 > html/css >>

简单的二级菜单

[html]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="daohang.aspx.cs" Inherits="_0A_ANXIN.daohang" %> 
 
<!DOCTYPE html> 
 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
    <title></title> 
    <script src="js/Jquery1.7.js"></script> 
    <script type="text/javascript"> 
        $(function () { 
            //*******************一级菜单点击****************** 
            var yijicaidan;//上一次点击的元素 
            $('.div_ul_li').click(function () { 
                $(this).css({ 'background-color': '#555' }); 
                $(this).unbind('mouseover').unbind('mouseout');//给点击的元素解绑,不再随着鼠标的变化而变化 
                $(this).parent().children('div:last').css('display', $(this).parent().children('div:last').css('display') == 'none' ? 'initial' : 'none'); 
                if (yijicaidan != null && yijicaidan.text() != $(this).text()) {//判断是不是同一个元素 
                    yijicaidan.css({ 'background-color': '#eee' });//初始化上一次点击的div的背景颜色 
                    yijicaidan.parent().children('div:last').css('display', 'none');//隐藏上一次点击的元素的二级菜单 
                    yijicaidan.bind('mouseover', function () { 
                        $(this).css({ 'background-color': '#aaa' }); 
                    })//给上一次点击的元素帮顶mouseover事件 
                    yijicaidan.bind('mouseout', function () { 
                        $(this).css({ 'background-color': '#eee' }); 
                    })//给上一次点击的元素帮顶mouseout事件 
                    yijicaidan = null; 
                } 
                yijicaidan = $(this); 
            }) 
            //*******************一级效果*********************** 
            $('.div_ul_li').bind('mouseover', function () { 
                $(this).css({'background-color':'#aaa'}); 
            }) 
            $('.div_ul_li').bind('mouseout', function () { 
                $(this).css({ 'background-color': '#eee' }); 
            }) 
 
 
            var erjicaidan;////上一次点击的元素 
            //********************二级菜单点击********************* 
            $('.div_ul_li_div ul li').click(function () { 
                if (erjicaidan!=null) { 
                    erjicaidan.css({ 'background-color': '#def' });//初始化所有的二级菜单背景 
                } 
                window.open($(this).children('input').val(), "content"); 
                $(this).css({ 'background-color': '#789' }).unbind('mouseover').unbind('mouseout'); 
                if (erjicaidan != null && erjicaidan.text() != $(this).text()) {//判断是不是同一个元素 
                    erjicaidan.css({ 'background-color': '#def' });//初始化上一次点击的div的背景颜色 
                    erjicaidan.bind('mouseover', function () { 
                        $(this).css({ 'background-color': '#abc' }); 
                    })//给上一次点击的元素帮顶mouseover事件 
                    erjicaidan.bind('mouseout', function () { 
                        $(this).css({ 'background-color': '#def' }); 
                    })//给上一次点击的元素帮顶mouseout事件 
                    erjicaidan = null; 
                } 
&n
补充:web前端 , HTML/CSS  ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,