ASP.NET MVC3:日期时间选择器无法工作
我无法让日期时间选择器工作。
在布局部分中,我
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
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
pluginhttp://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.
由于
datetimepicker()
不是 jQuery 核心的一部分,因此您需要向插件添加一个脚本引用,如下所示:之后,您应该将脚本块移出大括号并将其放置在下面的某个位置像这样的输入:
不过,您应该看看 EditorTemplates,它可以帮助您保持视图干净。
Since the
datetimepicker()
is not part of the jQuery core you need to add a script reference to the plugin like this:After this you should move the script block out of the curly brackets and place it somewhere beneath the input like this:
Nevertheless you should have a look at EditorTemplates, which helps you to keep your views clean.
还可以在
$(document).ready
中添加代码also add code inside
$(document).ready
我可以看到您已经包含了 jQuery 脚本,但是您是否还包含了 DateTimePicker 插件的脚本?
通过谷歌搜索,这似乎是您尝试使用的插件,因此您需要从那里下载
JS
,然后在当前 jQuery 脚本行下方添加以下行:建议将
标记移出 Razor代码块,因为它不需要在那里。将其放在
中或放在
标记之前。
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: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.