Jquery UI Datepicker IE IndexOf 错误

发布于 2024-11-28 12:08:14 字数 261 浏览 0 评论 0原文

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

IE7 中似乎存在问题抛出错误:

对象不支持属性或方法“indexOf”

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

哪位 javascript 专家可以帮我解决这个问题吗?

非常感谢, C

I have this code on jsFiddle. http://jsfiddle.net/crashdesk/GbUZ9/

There appears to be a problem in IE7 where it throws an error:

Object doesn't support property or method 'indexOf'

For the life of me I can't seem to fix it.

Can some javascript guru out there help me with this one.

Many thanks,
C

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

糖果控 2024-12-05 12:08:14

以某种黑客方式对其进行了排序。我必须为 IE7 创建一个字符串以及为所有其他浏览器创建一个数组。

使用这里的信息... http://minimalbugs.com/questions/share-solve-javascript-error-on-ie-lated-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');
        }

Got it sorted in a somewhat hack way. I had to create a string for IE7 aswell as the array for all other browsers.

Used information from here...http://minimalbugs.com/questions/share-solve-javascript-error-on-ie-related-to-indexof-function

Hopefully this will be of some help to someone else. Phew!

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');
        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文