【问题标题】:Create datetime picker in asp.net在 asp.net 中创建日期时间选择器
【发布时间】:2014-05-25 08:55:10
【问题描述】:

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

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

Microsoft JScript 运行时错误:对象不支持此属性 或方法

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

  <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 js库。
  • 请提供您的脚本包括
  • 嗨@Jai,我没听懂你,你能告诉我我需要做什么吗?
  • @IrvinDomininakaEdward,你想要什么脚本?
  • @Naruto 你必须解释为好像你正在使用.datepicker() 方法,只有在jquery 库之后包含jquery-ui.js 库时才可用。

标签: c# jquery asp.net asp.net-mvc asp.net-mvc-3


【解决方案1】:

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

在 jQuery 之后在页面中添加这些脚本标签:

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

通过这种方式,您可以将 jQuery UI 小部件绑定到 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/

【讨论】:

  • @Naruto 这是jsfiddle上的一个禁止资源错误,我会尽快修复它,在这里试试trentrichardson.com/examples/timepicker
  • 实际上上面的答案效果很好,我刚刚添加了
  • 但我给了你一个 +1,但我认为第一个是我的答案,它通过简单的复制过去起作用。您的回答也很有用,但我需要查看您提供的链接,非常感谢
【解决方案2】:

你添加了吗?

<head>
  <meta charset="utf-8">
  <title>jQuery UI Datepicker - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script>
  $(function() {
    $( "#datepicker" ).datepicker();
  });
  </script>
</head>

从您的 cmets 看,您似乎没有在页面顶部添加库和 api,请像我在这里发布的那样检查它

更多文档请查看http://jqueryui.com/datepicker/

【讨论】:

  • 嗨,谢谢 dholakiya,但是如何获得时间选择器?我只约会。时间呢
  • 对于我的信息,您必须为此切换时间选择器请检查此链接plugins.jquery.com/tag/timepicker
猜你喜欢
  • 2010-11-30
  • 2014-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-18
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多