Javascript Jquery hide不在内部工作。on()

Javascript Jquery hide不在内部工作。on(),javascript,jquery,html,Javascript,Jquery,Html,我正在将div帮助页面加载到index.html中的一个div中。加载在我的index.html页面上正常工作。问题是,一旦helppage div加载到index.html中,helpSection下的div就会出现,直到我能够单击其中一个div时才会消失。我想要的只是第一个显示的helpDiv和所有其他要隐藏的helpDiv,如果这是不可能的,那么就隐藏所有的div。我曾尝试使用jquery代码,但未能成功实现 任何帮助都将不胜感激 index.html <body>

我正在将div帮助页面加载到index.html中的一个div中。加载在我的index.html页面上正常工作。问题是,一旦helppage div加载到index.html中,helpSection下的div就会出现,直到我能够单击其中一个div时才会消失。我想要的只是第一个显示的helpDiv和所有其他要隐藏的helpDiv,如果这是不可能的,那么就隐藏所有的div。我曾尝试使用jquery代码,但未能成功实现

任何帮助都将不胜感激

index.html

<body>
    <div id="loadHelpHere"></div>
</body>

因此,在默认情况下,可以添加一个CSS类来隐藏它们,也可以在加载完成时将它们设置为隐藏

#helpSection > div {
    display : none;
}
您可以显示默认内容并删除内容,也可以只切换元素的可见性而不替换默认内容

在默认情况下希望隐藏的div上设置style=“display:none;”,然后设置$。稍后需要时显示它们

$(document).ready(function(){
    $( "#loadHelpHere" ).load( 'help.html #helpPage' );
    $( "#loadHelpHere" ).find('#helpSection').hide();
});

此外,您缺少div#loadHelpHere的结束标记

我会在每个
上设置
style=“display:none”
,但第一个“helpDiv”除外,或者放置一些css,如:

/* This will target classes containing the string "helpDiv" but not the class helpDiv */
[class*="helpDiv"]:not(.helpDiv) { 
    display: none;
}
然后对
执行类似操作。只需单击

$(document).on('click', '.justClick', function (e) {

    // This will hide all divs that contain a class matching "helpDiv"
    $('#helpSection [class*="helpDiv"]').hide();

    // Grab the index of the current .justClick
    var index = $(this).index() + 1;

    // Show the corresponding "helpDiv"
    $('#helpSection div.helpDiv' + index).show();

});

对我来说,它似乎工作得很好。当您单击“.justClick”时,它会隐藏所有其他div,并用正确div中的html替换“.helpDiv”。如果您想在页面加载时隐藏其他帮助div,则需要将其移出单击事件处理程序。
/* This will target classes containing the string "helpDiv" but not the class helpDiv */
[class*="helpDiv"]:not(.helpDiv) { 
    display: none;
}
$(document).on('click', '.justClick', function (e) {

    // This will hide all divs that contain a class matching "helpDiv"
    $('#helpSection [class*="helpDiv"]').hide();

    // Grab the index of the current .justClick
    var index = $(this).index() + 1;

    // Show the corresponding "helpDiv"
    $('#helpSection div.helpDiv' + index).show();

});