刷新页面后,jQuery日期选择器不起作用

时间:2015-08-03 12:52:41

标签: javascript jquery html5 twitter-bootstrap

我正在使用jQuery datepicker。没关系,当我从localhost在Firefox浏览器中运行我的项目时。过了一段时间,当我再次刷新Firefox时,没有显示jQuery datepicker。

在我运行它后,它没关系,但再次刷新它已经消失了。但是当我从其他位置(桌面)运行它,除了localhost它正常工作 这是我的.....

<div class="col-md-7 col-sm-7 col-xs-12 date-area-left">
 <label class="date-label" for="username">Choose a Date : <span class="star-icon-choose">*</span></label>
 <div style="width: 280px; font-family: 'Arial'; margin: auto;">
    <div class="some_datepicker" style="display: block"></div>
 </div>
</div>

这是JS ......

&#13;
&#13;
        <script type = "text/javscript>
             // Localization

            jQueryDatepicker.day_names_short = {
              1: 'Mon',
              2: 'Tue',
              3: 'Wed',
              4: 'Thu',
              5: 'Fri',
              6: 'Sat',
              7: 'Sun'
            };

            jQueryDatepicker.day_names = {
              1: 'Monday',
              2: 'Tuesday',
              3: 'Wednesday',
              4: 'Thursday',
              5: 'Friday',
              6: 'Saturday',
              7: 'Sunday'
            };

            jQueryDatepicker.month_names = {
              1: 'January',
              2: 'February',
              3: 'March',
              4: 'Apri',
              5: 'May',
              6: 'June',
              7: 'July',
              8: 'Agust',
              9: 'September',
              10: 'October',
              11: 'November',
              12: 'December'
            };

            $(document).ready(function() {
              var $selected = $('.selected');

              $some_datepicker = $('.some_datepicker');

              $some_datepicker.datepicker({
                next_button: '&gt;',
                prev_button: '&lt;'
              });

              $some_datepicker.setStartDate({
                year: 2015,
                // jquery.datepicker accepts first month as 1
                // (built-in Date() class accepts first month as 0)
                month: 1,
                day: 3
              });

              $some_datepicker.on('date_selected.datepicker', function(event, date) {
                $selected.show().html('Selected date is: ' + date.date.toString());
              });
            });
    </script>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:0)

document is "ready." jQuery检测到此准备状态之前,无法安全地操作页面。只有页面文档对象模型$( document ).ready()准备好执行JavaScript代码时,(DOM)中包含的代码才会运行。 $( window ).load(function() {...})中包含的代码将在整个页面(图片或iframe)(而不仅仅是DOM)准备就绪后运行。

$( document ).ready(function() {
    //Insert your code here and try. 
});