遍历ul li使用jQuery并存储当前导航项 [英] Looping over ul li's using jQuery and storing current nav item

查看:96
本文介绍了遍历ul li使用jQuery并存储当前导航项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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
        });

    }

});

感谢一堆!

推荐答案

如果要更改背景图像,我不明白为什么需要将它们存储在数组中.在 http://jsfiddle.net/h6GTW/处的以下工作示例将使您沿正确的方向前进.

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');
        });
    }
});?

这篇关于遍历ul li使用jQuery并存储当前导航项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆