jquery - 将 jquery 添加到 CSS 菜单

标签 jquery html css menu onhover

我有一个需要 jquery 的 css 菜单。可悲的是,我很难弄清楚。 下面是它的模型。当您将鼠标悬停在最顶部的菜单上时,将出现一个下拉菜单。 使用 jquery,如果您将鼠标悬停在其他子链接上并打开其子链接,则第一个子链接应打开其子链接然后切换类。

Mock up

Here is my fiddle: http://jsfiddle.net/ciancastillo/wtruM/

谢谢!

最佳答案

如果要向 HTML 元素添加 jQuery 函数,请使用 load()

 <script type="text/javascript">
     $('#idOfItem').load(function() {
          $("td").hover( 
               function () {
                    $(this).addClass("hover");
               }, 
               function () {
                    $(this).removeClass("hover");
          });
      });
 </script>

http://api.jquery.com/load-event/

如果您想绑定(bind)到整个类(比如 .dropdownItem),请使用不同的选择器:

 $('.dropdownItem').load(function() {
          //Your code here
      });

更多 jQuery 选择器:http://api.jquery.com/category/selectors/

添加或删除 CSS 类:http://api.jquery.com/removeClass/ http://api.jquery.com/addClass/

关于jquery - 将 jquery 添加到 CSS 菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15993551/

相关文章:

jquery - 使用 jQuery 检测整个页面上的删除键

javascript - 使用正则表达式在 jQuery 中将字符添加到字符串前面

html - canonical 标签可以用在所有页面上吗?

html - 如何修复无效的图片链接?

Python HTML 最小化器

html - 如何更改事件导航页面菜单的颜色

javascript - 如何通过隐藏/显示具有动态属性的 div 进行过滤?

css - 将多个 css 文件合并为一个

javascript 下拉菜单不起作用

javascript - fancybox 难以打开 html 页面