【发布时间】:2016-04-28 21:43:07
【问题描述】:
我在 localhost 中自定义了一个 Wordpress 主题,我的问题是必须单击下拉菜单才能展开/折叠,这是一个使用此主题的站点:http://mor10.com(您可以测试导航菜单以查看我是什么谈论)。 我需要在悬停和聚焦时使下拉菜单展开/折叠,但我真的是 jquery 的菜鸟,这里是下拉菜单的代码:
// Add menu items with submenus to aria-haspopup="true".
container.find( '.menu-item-has-children' ).attr( 'aria-haspopup', 'true' );
container.find( '.dropdown-toggle' ).click( function( e ) {
var _this = $( this ),
screenReaderSpan = _this.find( '.screen-reader-text' );
e.preventDefault();
_this.toggleClass( 'toggled-on' );
_this.next( '.children, .sub-menu' ).toggleClass( 'toggled-on' );
// jscs:disable
_this.attr( 'aria-expanded', _this.attr( 'aria-expanded' ) === 'false' ? 'true' : 'false' );
// jscs:enable
screenReaderSpan.text( screenReaderSpan.text() === screenReaderText.expand ? screenReaderText.collapse : screenReaderText.expand );
} );
}
initMainNavigation( $( '.main-navigation' ) );
【问题讨论】:
标签: jquery wordpress drop-down-menu