我有这个 jquery 代码可以在单击时切换子菜单。
jQuery(document).ready(function($){
$(".widget .menu-item-has-children").click(function () {
$(".widget .menu-item-has-children > .sub-menu").toggle();
});
});
但这会显示所有.子菜单,而不仅仅是单击的链接子菜单。我怎样才能用jquery“只对 child 这样做”?
最佳答案
jQuery(document).ready(function($){
$('.widget .menu-item-has-children').click(function () {
// `this` refers to the current `.widget .menu-item-has-children`
$(this).children('.sub-menu').toggle();
});
});
关于javascript - Jquery仅切换 child ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20179608/