我不确定如何准确地表达这个问题,所以这里是详细信息:
我在这里写的这个小东西:https://jsfiddle.net/f8thL83r/1/ 效果很好,只要您只想在顶部菜单中显示元素即可。
单击“图形设计”下的任何内容,它不会在右侧 Pane 中显示任何内容。为什么它适用于第一类而不适用于第二类?
这是一些代码。我知道我这样做的方式可能很糟糕,但我才刚刚开始适应 jQuery。
$('#Menu h3').click(function () {
$("#Menu ul ul").slideUp();
if (!$(this).next().is(":visible")) {
$(this).next().slideDown();
}
});
$('#Menu ul ul li a').click(function (e) {
var $currPage;
e.preventDefault();
$lastPage.hide();
var j = ($(this).parent().index()); //index of the li to show
var i = $(this).parent().parent().parent().index(); //index of the ul to show
$currPage = $('#ServMain .list' + i).find('.page' + j);
$currPage.show();
$lastPage = $currPage;
});
最佳答案
似乎所选页面的其他 HTML 元素不可见。
下面的代码应该修复它们
$('#Menu ul ul li a').click(function (e) {
e.preventDefault();
$lastPage.hide();
var j = ($(this).parent().index());
var i = $(this).parent().parent().parent().index();
$('#ServMain ul').not('.list'+i).hide();
$lastPage = $('#ServMain .list' + i).find('.page' + j);
$lastPage.parent().show();
$lastPage.show();
$lastPage.find('div').show();
});
关于javascript - jQuery .find() 选择正确的元素但不显示它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31016027/