Javascript 如果类处于活动状态,则更改div上的文本

Javascript 如果类处于活动状态,则更改div上的文本,javascript,jquery,class,Javascript,Jquery,Class,欢迎光临。一开始我想告诉我们,我的英语很差:-) 因此,我在wordpress上创建网站支持时遇到了问题。我的主题是fullpane,其中是section <section id="homepage" class="clearfix section-post section-category-136 section-category-home-page default fullwidth post-16824 section type-section status-publish hent

欢迎光临。一开始我想告诉我们,我的英语很差:-) 因此,我在wordpress上创建网站支持时遇到了问题。我的主题是fullpane,其中是section

<section id="homepage" class="clearfix section-post section-category-136 section-category-home-page default fullwidth post-16824 section type-section status-publish hentry ***active*** fullpage-active" data-anchor="homepage" style="height: 979px; padding: 0px 0px 70px; line-height: 894px;">

我们可以看到“活动”这个名字是自动生成的,我想我可以用它来解决我的问题

我想在右侧窗口创建一些类似索引“1代表5节”的固定位置,当我滚动到底部时,数字应该更改为“2代表5节” 所以我创建了jquery

<script type="text/javascript">
    $( document ).ready(function() {
        if($( "#homepage" ).hasClass( "active" )){
            $("div#date").text("2 for 5");
        }
    });
</script>

$(文档).ready(函数(){
if($(“#主页”).hasClass(“活动”)){
$(“div#date”)。文本(“2代表5”);
}
});
而且工作不正常。 此页面位于地址emotivo.pl/nowe


如果我忘了告诉我们一些重要的事情,请告诉我。

更新

将脚本修改为:

<script>
$(window).scroll(function(){
    var children = $("#superContainer").children(); 
    $(children).each(function(index,value) {
    if($(value).hasClass("active"))
        $("div#date").html(index+" of "+ children.length);
  });
});
</script>

$(窗口)。滚动(函数(){
var children=$(“#超级容器”).children();
$(子项)。每个(函数(索引、值){
if($(值).hasClass(“活动”))
$(“div#date”).html(索引+”of“+childrence.length);
});
});

如果您的网站覆盖了滚动功能,那么复制粘贴可能无法实现这一点,但核心逻辑是相同的

不幸的是,这不管用。一切都变了。如果我将'active'更改为'post-16824'开始工作。它应该看起来像$(document).ready(function(){If($(“#homepage”).hasglass('active”){$('div#date”).html(“2代表5”)}if($(“#welcome”).hasglass(“active”){$(“div#date”).html(“3代表5”);});在那里我更新了我的答案。检查这是否有效。我不知道发生了什么事。这个脚本是粘贴到页脚前体结束标记,我认为它可以是吗?目前它工作不正常,当我在网站加载时触摸滚动条,然后这个div中的文本会发生变化,但当我不触摸滚动条时,没有任何变化。即使它会改变,向下滚动后也不会改变,它会保持0/5。也许我会给你更多关于这个页面的信息?我不知道