1

私の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
4

1 に答える 1

0

おそらく関数var event;の開始時に欠落していshoweventsます。コメントを参照してください:

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);
    }
}
于 2013-03-18T12:11:05.730 に答える