【问题标题】:Jquery UI Datepicker IE IndexOf errorJquery UI Datepicker IE IndexOf 错误
【发布时间】:2011-08-09 08:39:50
【问题描述】:

我在 jsFiddle 上有这段代码。 http://jsfiddle.net/crashdesk/GbUZ9/

在 IE7 中似乎存在问题,它会引发错误:

对象不支持属性或方法'indexOf'

对于我的生活,我似乎无法修复它。

那里的一些 javascript 专家可以帮我解决这个问题。

非常感谢, C

【问题讨论】:

    标签: jquery jquery-ui uidatepicker jquery-ui-datepicker


    【解决方案1】:

    以一种有点骇人听闻的方式对其进行了排序。我必须为 IE7 创建一个字符串以及所有其他浏览器的数组。

    从这里使用的信息...http://minimalbugs.com/questions/share-solve-javascript-error-on-ie-related-to-indexof-function

    希望这对其他人有所帮助。呸!

    var months = ["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];
                var months2 = "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec";
    
                    // initialise the "Select date" link
                    $('#date-pick')
                        .datePicker(
                            // associate the link with a date picker
                            {
                                createButton:false,
                                endDate:'31/12/2012'
                            }
                        ).bind(
                            // when the link is clicked display the date picker
                            'click',
                            function()
                            {
                                updateSelects($(this).dpGetSelected()[0]);
                                $(this).dpDisplay();
                                return false;
                            }
                        ).bind(
                            // when a date is selected update the SELECTs
                            'dateSelected',
                            function(e, selectedDate, $td, state)
                            {
                                updateSelects(selectedDate);
                            }
                        ).bind(
                            'dpClosed',
                            function(e, selected)
                            {
                                updateSelects(selected[0]);
                            }
                        );
    
                    var updateSelects = function (selectedDate)
                    {
                        var selectedDate = new Date(selectedDate);
                        $('#d option[value=' + selectedDate.getDate() + ']').attr('selected', 'selected');
                        $('#m option[value=' + (months[selectedDate.getMonth()]) + '-' +  (selectedDate.getFullYear()) + ']').attr('selected', 'selected');
                    }
                    // listen for when the selects are changed and update the picker
                    $('#d, #m')
                        .bind(
                            'change',
                            function()
                            {
                                var d = new Date(
                                            $('#m').val().split("-")[1],
                                            months2.indexOf($('#m').val().split("-")[0]),
                                            $('#d').val()
                                        );
                                $('#date-pick').dpSetSelected(d.asString());
    
                            }
                        );
    
                    // default the position of the selects to today
                    var today = new Date();
                    updateSelects(today.getTime());
    
                    // and update the datePicker to reflect it...
                    $('#d').trigger('change');
            }
    

    【讨论】:

      【解决方案2】:

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-26
      • 1970-01-01
      相关资源
      最近更新 更多