带有添加事件的html日历(datepicker)

时间:2013-05-06 16:22:30

标签: javascript html datepicker

您好我希望允许用户将事件添加到日历中(目前使用日期选择器),方法是在文本框中输入数据,然后点击日历上的日期然后点击提交。我想要突出显示事件,当点击日期时(上面有一个事件),事件会弹出信息。

试图搜索,但我没有运气。

谢谢

编辑:更改了一些代码,以便正确编译

我还想简单地引用所选的日期,以便我可以用它来记录数据。要使用此程序,只需键入您的值而不是命中刷新,新值将加载到5月13日。

<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>jQuery &amp; jQueryUI Base - jsFiddle demo</title>

  <script type='text/javascript' src='http://code.jquery.com/jquery-1.5.js'></script>
  <link rel="stylesheet" type="text/css" href="/css/normalize.css">


  <link rel="stylesheet" type="text/css" href="/css/result-light.css">


      <link rel="stylesheet" type="text/css" href="http://ajax.microsoft.com/ajax/jquery.ui/1.8.7/themes/black-tie/jquery-ui.css">





      <script type='text/javascript' src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.9/jquery-ui.js"></script>


  <style type='text/css'>
    table.ui-datepicker-calendar tbody td.highlight > a {
    background: url("images/ui-bg_inset-hard_55_ffeb80_1x100.png") repeat-x scroll 50% bottom #FFEB80;
    color: #363636;
    border: 1px solid #FFDE2E;
}

  </style>



<script type='text/javascript'>//<![CDATA[ 
$(window).load(function(){
var equip = document.getElementById('equipment').value;
var size = document.getElementById('size').value;
var surface = document.getElementById('surface').value;
var orderNumber = document.getElementById('orderNumber').value;
var responsible = document.getElementById('responsible').value;
var events = [ 
    { Title: "Equipment: " + equip + "\nSize: " + size, Date: new Date("05/13/2013") }, 
    { Title: "Dinner", Date: new Date("02/25/2011") }, 
    { Title: "Meeting with manager", Date: new Date("03/01/2011") }
];



$("div").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', null];
        }
        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) {
            alert(event.Title);
        }
    }
});
});//]]>
addLow()

</script>


</head>
<body>
Equipment: <input type='text' id='equipment' /> <br />
Size: <input type='text' id='size' /> <br />
Required on Surface: <input type='radio' id='surface' /> <br />
Work Order Number: <input type='text' id='orderNumber' /> <br />
Responsible: <input type='text' id='responsible' /> <br />
  <div></div>
<button type="button" onclick="addLow()">Add Lowering Event</button><br>

</body>


</html>

0 个答案:

没有答案