zoukankan      html  css  js  c++  java
  • jQuery鼠标事件例子1的改进

    <script type="text/javascript">
    $(function() {
    $("div#leftMenu")
    .css("background-color", "chartreuse")
    .css("border", "dotted thin red")
    .css("width", "280px")

    $("div#leftMenu>ul>li~div")
    .css("display", "none");

    function fnClick() {
    $("div#leftMenu>ul>li~div")
    .css("display", "none");
    $(this).next()
    .css("display", "block");
    }

    $("div#leftMenu>ul>li")
    .bind({
    click: fnClick,
    mouseover: function() {
    $(this)
    .css("background-color", "orange")
    .css("color", "white")
    .css("font-weight", "bold");

    },
    mouseout: function() {
    $(this)
    .css("background-color", "lightskyblue")
    .css("color", "black")
    .css("font-weight", "normal");
    }
    });
    $("dd")
    .bind({
    mouseover: function() {
    $(this)
    .css("background-color", "pink")
    .css("color", "blueviolet")
    .css("font-weight", "bold");
    },
    mouseout: function() {
    $(this)
    .css("background-color", "chartreuse")
    .css("color", "black")
    .css("font-weight", "normal");
    }
    });
    });
    </script>
    <style type="text/css">
    ul {
    padding: 0px;
    margin: 0px;
    }

    li {
    list-style: none;
    padding: 10px;
    margin: 2px;
    text-align: center;
    background-color: lightskyblue;
    }

    dd {
    padding: 4px;
    margin: 3px;
    text-align: center;
    }

    a:hover,
    a:active,
    a:link {
    text-decoration: none;
    color: white;
    }
    </style>
    </head>

    <body>
    <div id="menu">
    <table border="0" cellpadding="0" cellspacing="0">
    <tr style="background-color: darkblue;">
    <th>&nbsp;</th>
    <th width="20">
    <a href="#" onclick="$('#menu').hide();">×</a>
    </th>
    </tr>
    <tr>
    <th colspan="2">
    <div id="leftMenu">
    <ul>
    <li>菜单一</li>
    <div class="subMenu">
    <dd>子菜单11</dd>
    <dd>子菜单12</dd>
    <dd>子菜单13</dd>
    <dd>子菜单14</dd>
    </div>
    <li>菜单二</li>
    <div class="subMenu">
    <dd>子菜单21</dd>
    <dd>子菜单22</dd>
    <dd>子菜单23</dd>
    <dd>子菜单24</dd>
    </div>
    <li>菜单三</li>
    <div class="subMenu">
    <dd>子菜单31</dd>
    <dd>子菜单32</dd>
    <dd>子菜单33</dd>
    <dd>子菜单34</dd>
    </div>
    <li>菜单四</li>
    <div class="subMenu">
    <dd>子菜单41</dd>
    <dd>子菜单42</dd>
    <dd>子菜单43</dd>
    <dd>子菜单44</dd>
    </div>
    <li>菜单五</li>
    <div class="subMenu">
    <dd>子菜单51</dd>
    <dd>子菜单52</dd>
    <dd>子菜单53</dd>
    <dd>子菜单54</dd>
    </div>
    </ul>
    </div>
    </th>
    </tr>
    </table>
    </div>
    <input type="button" value="菜单" onclick="$('#menu').show();" />
    <input type="button" value="撤销" onclick="$('div#leftMenu>ul>li,dd').unbind();" />
    <p>jQuery鼠标事件例子2:在例子1的基础上多运用了bind()--绑定多个事件,在菜单按钮部分运用了show(),在右上角的叉号运用了hide()方法,在撤销按钮运用了unbind()方法--移出事件。</p>
    </body>

  • 相关阅读:
    fgets()函数读取键盘,去掉换行符或丢弃多余的字符
    c语言gets()函数与它的替代者fgets()函数
    基于京东手机销售数据用回归决策树预测价格
    「我去,这也能行!」令人惊叹的8个深度学习应用
    常见数据结构的 Python 实现(建议收藏)
    60 分钟极速入门 PyTorch
    大牛推荐的15本学习数据分析挖掘的好书
    排名前20的网页爬虫工具
    如何11 周打造全能Python工程师!
    初学者的编程自学指南
  • 原文地址:https://www.cnblogs.com/tian-xin/p/8203930.html
Copyright © 2011-2022 走看看