If 样式 jQuery 语句帮助
我正在使用一个 CMS 网站,该网站使用水平主导航和侧边栏样式子导航。
水平菜单项用于网站的部分,例如关于我们、我们的工作等,侧边栏子导航用于与该部分相关的内容。
一旦用户单击水平菜单项之一并显示该部分的内容和侧边栏导航,我想将一个类应用于与该部分相关的水平菜单项,无论他们单击哪个侧边栏菜单项。
为了实现这一点,每个侧边栏菜单项都分配有一个唯一的类,所以本质上我想用 jQuery 创建的是......
如果“ul.about-sidebar”显示在页面上,则将类“active”添加到水平方向关于我们菜单项。
但我有点不确定如何措辞该声明......有什么想法吗?
I have a CMS site that I am working that utilises a horizontal main navigation and a sidebar style sub navigation.
The horizontal menu items are for the sections of the site like about us, our work etc. and the sidebar sub nav is for the content relating to that section.
Once a user clicks on one of the horizontal menu items and is presented with the content and sidebar nav for that section I would like to apply a class to the horizontal menu item relating to that section regardless of what sidebar menu item they click.
To achieve this, each sidebar menu item has a unique class assigned to it so essentially what I would like to create with jQuery is...
If "ul.about-sidebar" is displayed on page then add class "active" to the horizontal About Us menu item.
But i'm a little unsure as to how to word the statement...any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
类似的东西应该可以工作
如果
关于我们
菜单项没有唯一的ID,您可能可以使用如下选择器找到它:Thislooks for an element with class
'menuItem' 在带有
Id="horizontalMenu"
的元素下包含文本"About Us"
Something like that should work
If the
About Us
menu item doesn't have a unique Id you can probably find it using a selector like:This looks for an element with class
'menuItem'
containing the text"About Us"
under the element withId="horizontalMenu"
这应该适用于您单击的任何 ul 元素。区分
元素是可以的,所以最好水平导航栏中的所有元素都按类选择,如
$('ul.horiz-navbar')
。This should apply to any ul element you click. It is OK to make distinction of
<ul>
elements, so maybe it's better that all the elements in the horizontal navbar are selected by class like$('ul.horiz-navbar')
.