asp.net mvc 日期选择器不工作
我使用pluralsight视频做了这个例子,但日期选择器没有出现。
第一。我创建了模板。
@model System.DateTime?
@Html.TextBox("",ViewData.TemplateInfo.FormattedModelValue,new {
data_datepicker = true
});
第二。我在 .js 文件中创建了该行,
$(document).ready(function () {
$(":input[data-datepicker]").datepicker();
}
这应该就是让它根据视频工作的全部内容。
- 当然我还包括 jquery 文件
<前><代码>> <脚本 src="@Url.Content("~/Scripts/jquery.validate.min.js")" >类型 =“text/javascript”> <脚本 > src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" >类型 =“text/javascript”> <脚本 > src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" >类型 =“text/javascript”> <脚本 > src="@Url.Content("~/Scripts/HR.js")" type="text/javascript">;
完整的 html 结果(已恢复)看起来不错:
<html><head>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.4.min.js" type="text/javascript"></script>
</head>
<body>
<script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui-1.8.11.min.js" type="text/javascript"></script>
<script src="/Scripts/HR.js" type="text/javascript"></script>
<form action="/ApplicantPosition/Create" enctype="multipart/form-data" method="post"> <fieldset>
<div class="editor-label">
<label for="appliedDate">Date applied</label>
</div>
<div class="editor-field">
<input data-datepicker="True" data-val="true" data-val-required="Applied date is required" id="appliedDate" name="appliedDate" type="text" value="" />;
</body>
</html>
I did this example using the pluralsight video but the date picker is just not appearing.
1st. I created the template.
@model System.DateTime?
@Html.TextBox("",ViewData.TemplateInfo.FormattedModelValue,new {
data_datepicker = true
});
2nd. I created the line in my .js file
$(document).ready(function () {
$(":input[data-datepicker]").datepicker();
}
That should be all to make it work according to the video.
- I am also including the jquery files of course
> <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" > type="text/javascript"></script> <script > src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" > type="text/javascript"></script> <script > src="@Url.Content("~/Scripts/jquery-ui-1.8.11.min.js")" > type="text/javascript"></script> <script > src="@Url.Content("~/Scripts/HR.js")" type="text/javascript"></script>
The complete resulting html (resumed) seems fine:
<html><head>
<script src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.4.min.js" type="text/javascript"></script>
</head>
<body>
<script src="/Scripts/jquery.validate.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery.validate.unobtrusive.min.js" type="text/javascript"></script>
<script src="/Scripts/jquery-ui-1.8.11.min.js" type="text/javascript"></script>
<script src="/Scripts/HR.js" type="text/javascript"></script>
<form action="/ApplicantPosition/Create" enctype="multipart/form-data" method="post"> <fieldset>
<div class="editor-label">
<label for="appliedDate">Date applied</label>
</div>
<div class="editor-field">
<input data-datepicker="True" data-val="true" data-val-required="Applied date is required" id="appliedDate" name="appliedDate" type="text" value="" />;
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您没有关闭文档就绪功能。尝试这样:
注意我的脚本末尾的附加
);
,而您的脚本中缺少它。You are not closing the document ready function. Try like this:
Notice the additional
);
at the end of my script which is missing in yours.我认为你应该这样做:
如果你使用属性等于选择器。
我会做:
编辑 - 你的函数中有一个错误(你忘记了结束
);
)I think you should do:
if you are using the attribute equals selector.
I'd do:
edit - ther is an error in your function (you forgot the closing
);
)