ReferenceError:事件未定义

本文关键字:未定义 事件 ReferenceError | 更新日期: 2023-09-27 18:04:22

在我的asp.net mvc3页面中,我使用jquery来显示一个日历来显示数据库中添加的事件。它在google chrome中工作正常,但在firefox 19.0.2中显示如下错误

  <script type="text/javascript" src="@Url.Content("~/Scripts/jquery-1.8.3.js")">   </script>
  <script type="text/javascript" src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-i.css">         
<link rel="stylesheet" href="../../Content/css/styleui.css" />   
   <script type="text/javascript">
        $(document).ready(function () {
            $.getJSON("/Page/dates", null, function (data) {
                var s = eval(data);
                alert(s);
                showevents(s);
            });
            function showevents(events) {
                $("#datepicker").datepicker({
                beforeShowDay: function (date) {
                    var result = [true, '', null];
                    var matching = $.grep(events, function (event) {
                        return event.Date.valueOf() === date.valueOf();
                    });
                    if (matching.length) {
                        result = [true, 'highlight', event.Title];
                    }
                    return result;
                },
                onSelect: function (dateText) {
                    var date, selectedDate = new Date(dateText), i = 0, event = null;
                    while (i < events.length && !event) {
                        date = events[i].Date;
                        if (selectedDate.valueOf() === date.valueOf()) {
                            event = events[i];
                        }
                        i++;
                    }
                    if (event) {
                        //return [true, "Highlighted", event.Title];
                        alert(event.Title);
                    }
                }
            });
        }
    });
</script>

,

<div id="datepicker">

,

[16:35:16.336] ReferenceError: event is not defined @ http://code.jquery.com/jquery-1.8.3.js:579

ReferenceError:事件未定义

您可能在showevents功能开始时遗漏了var event;。看到评论:

beforeShowDay: function (date) {
    var result = [true, '', null];
    var matching = $.grep(events, function (event) {
        return event.Date.valueOf() === date.valueOf();
    });
    if (matching.length) {
        // event is not defined
        result = [true, 'highlight', event.Title];
    }
    return result;
},
onSelect: function (dateText) {
    var date, selectedDate = new Date(dateText), i = 0, event = null;
    while (i < events.length && !event) {
        date = events[i].Date;
        if (selectedDate.valueOf() === date.valueOf()) {
            // event is not defined
            event = events[i];
        }
        i++;
    }
    if (event) {
        //return [true, "Highlighted", event.Title];
        // event is not defined
        alert(event.Title);
    }
}