简体   繁体   English

jQuery脚本无法刷新页面

[英]Jquery script not working on page refresh

I have a jquery script to add a class to a div 我有一个jquery脚本将一个类添加到div

jQuery('.responsive-calendar .today a').addClass('selectedDay');

This script works on the initial load of the page and adds the class. 该脚本在页面的初始加载时起作用并添加类。 But on refreshing the page, this doesn't work and the class is not added. 但是在刷新页面时,这不起作用,并且未添加类。

So is there any function that I can use to load this script on the page refresh. 因此,有什么功能可以用来在页面刷新时加载此脚本。 I have tried adding this to the following function, but with no luck. 我尝试将其添加到以下功能中,但是没有运气。

jQuery(window).bind("load", function() {...});
jQuery(window).load(function(){...});
jQuery(window).on('load',function() { ... });

Am I missing something here? 我在这里想念什么吗?

Use jQuery(document).ready() 使用jQuery(document).ready()

Example: 例:

(function($) {
    $(document).ready(function() {
        $('.responsive-calendar .today a').addClass('selectedDay');
    });
})(jQuery);

UPDATE: For your calendar, use its onInit() callback! 更新:对于您的日历,请使用其onInit()回调!

Example: 例:

(function($) {
    $(document).ready(function() {
        $('.responsive-calendar').responsiveCalendar({
            onInit: function() {
                $('.responsive-calendar .today a').addClass('selectedDay');
            }
        });
    });
})(jQuery);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM