Skip to main content
 首页 » 编程设计

c#之在 asp.net 中创建日期时间选择器

2024年02月13日11jillzhang

我正在尝试在 asp.net 中创建这样的日期选择器,但它向我抛出错误。我正在使用 MVC 架构来创建。

这是我正在使用的代码。我收到错误信息:

Microsoft JScript runtime error: Object doesn't support this property or method

我需要选择日期并坐在编辑文本中。

  <tr> 
    <td style="width: 450px" class="" height="40px"> 
                            <%= Html.TextBox(ViewControlNames.DateTime, "", new { maxlength = "40", id = ViewControlNames.DateTime, Class = "LongInputField" })%> 
                    </td> 
    </tr> 
 
         <script> 
             $(function () { 
                 $("#CabDateTime").datepicker(); 
             }); 
        </script> 
 
    </asp:Content> 

请您参考如下方法:

可能您没有包含必要的 jQuery UI 库。

在 jQuery 之后将这些脚本标记添加到您的页面中:

<link rel="stylesheet" href="css/themename/jquery-ui.custom.css" /> 
<script src="js/jquery-ui.custom.min.js"></script> 

通过这种方式,您可以将 jQuery UI 小部件绑定(bind)到 jQuery。

引用:https://learn.jquery.com/jquery-ui/getting-started/

如果你需要一个日期时间选择器;您可以使用通过添加时间选择来扩展日期选择器功能的小部件插件。

项目地址:http://trentrichardson.com/examples/timepicker/

演示代码:

$(document).ready(function () { 
    $('#timePicker').datetimepicker({ 
        controlType: 'select', 
        timeFormat: 'hh:mm ss' 
    }); 
}); 

演示:http://jsfiddle.net/IrvinDominin/Ljt4T/1/