我为下拉菜单找到了以下 jquery 代码。HTML 代码应该包含什么才能使用它?
jQuery(document).ready(function(){
jQuery("html").bind("click", function (e) {
jQuery('.dropdown-toggle, a.menu').parent("li").removeClass("open");
});
jQuery(".dropdown-toggle, a.menu").click(function(e) {
// First look an see if a menu is open. If it is, then just close it.
if (jQuery(this).parent("li").hasClass("open")) {
jQuery("ul").find('li').removeClass('open');
}
// If menu was not open, then close any other menus that were open and just open the one.
else {
jQuery("ul").find('li').removeClass('open');
jQuery(this).parent("li").addClass('open');
}
return false;
});
});