使用 jQuery 循环 ul li's 并存储当前导航项

发布于 2024-09-25 05:39:50 字数 922 浏览 2 评论 0原文

我循环遍历 UL 中的第一组 li a 标签并获取高度,以便在 a > 时我可以提供不同的背景图像。跨度> span 文本跨两行或三行换行。

我需要能够将这些特定按钮存储在数组中,以便当我将鼠标悬停在它们上时,具有双行文本的当前范围会收到不同的背景图像。

这就是我所拥有的,我不知道从这里去哪里。我会很感激一些帮助。

   var doubleLineButtons = new Array();

$("div.subSectNav .RadPanelBar ul.rpRootGroup > li.rpItem > a").each(function (i) {

    if ($(this).height() > 35) {

        doubleLineButtons.push($(this))

        // here I need to access any possible menu items if the lines have wrapped and deliver a different background image
        doubleLineButtons[i].hover(function(){
            // change the background image of this button
            (this).css('background', 'url("/App_Themes/2010a/images/background_nav_sub_left_double.png") no-repeat scroll 0 0 transparent');
        },
        function(){
            // remove the background image from this button
        });

    }

});

非常感谢!

I am looping over the first set of li a tags in my UL and getting the height so that I can deliver a different background image if the a > span > span text wraps across two or three lines.

I need to be able to store these specific buttons in an array, so that when I mouse over them, the current span with double line text receives a different background image.

Here's what I have and I am not sure where to go from here. I'd appreciate some help.

   var doubleLineButtons = new Array();

$("div.subSectNav .RadPanelBar ul.rpRootGroup > li.rpItem > a").each(function (i) {

    if ($(this).height() > 35) {

        doubleLineButtons.push($(this))

        // here I need to access any possible menu items if the lines have wrapped and deliver a different background image
        doubleLineButtons[i].hover(function(){
            // change the background image of this button
            (this).css('background', 'url("/App_Themes/2010a/images/background_nav_sub_left_double.png") no-repeat scroll 0 0 transparent');
        },
        function(){
            // remove the background image from this button
        });

    }

});

Thanks a bunch!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小耗子 2024-10-02 05:39:50

如果您只想更改背景图像,我不明白为什么需要将它们存储在数组中。 http://jsfiddle.net/h6GTW/ 中的以下工作示例应该可以帮助您沿着正确的路线前进。

$('li').each(function() {
    if ($(this).height() > 35) {
        $(this).hover(function() {
            $(this).css('background', 'red');
        }, function() {
            $(this).css('background', 'white');
        });
    }
});?

I don't see why you need to store them in an array if all you are wanting to do is change the background image. The following working example at http://jsfiddle.net/h6GTW/ should get you going along the right lines.

$('li').each(function() {
    if ($(this).height() > 35) {
        $(this).hover(function() {
            $(this).css('background', 'red');
        }, function() {
            $(this).css('background', 'white');
        });
    }
});?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文