ASP.NET MVC3:日期时间选择器无法工作

发布于 2024-12-16 14:30:26 字数 975 浏览 1 评论 0原文

我无法让日期时间选择器工作。

在布局部分中,我

<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>

认为:

@{
    ViewBag.Title = "Insert Task";
    <script type="text/javascript">
        $('#ActionDateTime').datetimepicker();
    </script>
}

这是我的字段

@Html.Label("Action Date") @Html.TextBox("ActionDateTime")

编辑:

因此,应用更改后页面源现在看起来像这样: 在我的头部:(这是正确链接的,单击链接打开js文件)

<script src="/Scripts/jquery-ui-timepicker-addon.js" type="text/javascript"></script>

,我的身体:

    <input id="ActionDateTime" name="ActionDateTime" type="text" value="" />
    <script type="text/javascript">
        $(document).ready(function () {

            $('#ActionDateTime').datetimepicker();


        });

    </script>

仍然无法工作。

I cant get the datetime picker working.

In the layout partial I have

<script src="@Url.Content("~/Scripts/jquery-1.5.1.min.js")" type="text/javascript"></script>

In my view:

@{
    ViewBag.Title = "Insert Task";
    <script type="text/javascript">
        $('#ActionDateTime').datetimepicker();
    </script>
}

Here is my field

@Html.Label("Action Date") @Html.TextBox("ActionDateTime")

EDIT:

So the page source now looks like this after applying changes:
In the head I have : (this is linked correctly, clicking link opens js file)

<script src="/Scripts/jquery-ui-timepicker-addon.js" type="text/javascript"></script>

and the body I have :

    <input id="ActionDateTime" name="ActionDateTime" type="text" value="" />
    <script type="text/javascript">
        $(document).ready(function () {

            $('#ActionDateTime').datetimepicker();


        });

    </script>

Still not working.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

殊姿 2024-12-23 14:30:26

datetimepicker 不是 jQuery 核心库的一部分。您需要将此脚本与 jQuery UI 库一起包含在内。

datetimepicker 插件
http://trentrichardson.com/examples/timepicker/js/jquery -ui-timepicker-addon.js

jQuery UI 库 http://jqueryui.com/download

将两者包含在您的 head/or foot 部分中,只要您有 jQuery 库的引用,但位于 jQuery 库引用的下方。

还包括 jQuery UI 样式表,具体取决于您选择的样式。

datetimepicker is not part of the jQuery core library. You need to include this script along with the jQuery UI library.

datetimepicker plugin
http://trentrichardson.com/examples/timepicker/js/jquery-ui-timepicker-addon.js

jQuery UI library http://jqueryui.com/download

Include both in your head/or foot section where ever you have the reference to the jQuery library, BUT below the jQuery library reference.

Also include the jQuery UI stylesheet depending on the style you have selected.

倾`听者〃 2024-12-23 14:30:26

由于 datetimepicker() 不是 jQuery 核心的一部分,因此您需要向插件添加一个脚本引用,如下所示:

<script src="@Url.Content("~/Scripts/jquery-datetimepicker.min.js")" type="text/javascript"></script>

之后,您应该将脚本块移出大括号并将其放置在下面的某个位置像这样的输入:

@Html.TextBox("ActionDateTime")
<script type="text/javascript">
    $('#ActionDateTime').datetimepicker();
</script>

不过,您应该看看 EditorTemplates,它可以帮助您保持视图干净。

Since the datetimepicker() is not part of the jQuery core you need to add a script reference to the plugin like this:

<script src="@Url.Content("~/Scripts/jquery-datetimepicker.min.js")" type="text/javascript"></script>

After this you should move the script block out of the curly brackets and place it somewhere beneath the input like this:

@Html.TextBox("ActionDateTime")
<script type="text/javascript">
    $('#ActionDateTime').datetimepicker();
</script>

Nevertheless you should have a look at EditorTemplates, which helps you to keep your views clean.

挽袖吟 2024-12-23 14:30:26

还可以在 $(document).ready 中添加代码

<script type="text/javascript">

$(document).ready(function(){

 $('#ActionDateTime').datetimepicker();


});

</script>

also add code inside $(document).ready

<script type="text/javascript">

$(document).ready(function(){

 $('#ActionDateTime').datetimepicker();


});

</script>
半仙 2024-12-23 14:30:26

我可以看到您已经包含了 jQuery 脚本,但是您是否还包含了 DateTimePicker 插件的脚本?

通过谷歌搜索,似乎是您尝试使用的插件,因此您需要从那里下载 JS,然后在当前 jQuery 脚本行下方添加以下行:

<script src="@Url.Content("~/Scripts/jquery-ui-timepicker-addon.js")" type="text/javascript"></script>

建议将

I can see you have included the jQuery script, but have you also included the script for the DateTimePicker plugin?

From googling, this appears to be the plugin you're trying to use, so you'll need to download the JS from there, then add the following line underneath your current jQuery script line:

<script src="@Url.Content("~/Scripts/jquery-ui-timepicker-addon.js")" type="text/javascript"></script>

It would also be advisable to move your <script> tag out of the Razor code block, as there's no need for it to be there. Put it either in the <head> or just before the </body> tag.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文