jquery - 将鼠标悬停在父项上时如何切换内部内容

标签 jquery html css

当鼠标悬停在父级 LI 上时,如何添加一个脚本来扩展“section # inner”UL。

例如,将鼠标悬停在“Section 1”上将切换“Section 1 INNER”LI/UL。
我想让它动态化,因为我可能对“第 3 节”或“第 2 节”有相同的内容

JSFiddle:http://jsfiddle.net/34ng9sto/1/
查询:

    $(function () {
    $(".uSPInner").hide();
    if (!$(".uSPInner").is(":visible")) {
        $(this).closest("li").hide(); //hides the "LI" which gives the extra line... Not working.
        //alert("test");
    }
});

例子:

<ul>
    <li></li> //this will toggle the below LI because it has a nested UL
    <li> //hide this by default and toggle when hovered over the LI above it.
        <ul>
            <li></li>
            <li></li>
        </ul>
    </li>
    <li></li> //show this by default
    <li></li> //show this by default
</ul>

最佳答案

以这种方式使用 JavaScript:

$(function () {
    $(".uSPInner").hide();
    if (!$(".uSPInner").is(":visible")) {
        $(this).closest("li").hide();
        //alert("test");
    }
    $(".clickMe").closest("li").hover(function () {
        $(this).closest("li").find("ul").slideDown();
    }, function () {
        $(this).closest("li").find("ul").slideUp();
    });
});

fiddle :http://jsfiddle.net/34ng9sto/6/

关于jquery - 将鼠标悬停在父项上时如何切换内部内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31163413/

相关文章:

javascript - 如何使下拉列表不可选择?

javascript - 使用 jquery 在 div 中添加、调整大小、位置、颜色更改文本

javascript - 无法将隐藏的表单值获取到 javascript 变量中

html - 当元素尺寸未知时强制在 Flexbox 中设置断点?

javascript - 在我的网站上显示脚本的值

html - 在 <nav> 标签下使用 css 垂直菜单时遇到问题

javascript - 无法使用 "window.onbeforeunload"更改网页位置

javascript - 为什么此动画不显示以阻止不起作用?

javascript - 对于响应式网格有什么建议可以适应不同浏览器的文本大小和布局吗?

html - 标题和部分相互合并/重叠