使用 jQuery 循环 ul li's 并存储当前导航项
我循环遍历 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您只想更改背景图像,我不明白为什么需要将它们存储在数组中。 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.