如何从DatePicker ui jquery中删除时间
我正在使用带有asp.net mvc的jquery ui日期选择器,当网页打开时,它会在日期选择器的文本框中显示日期和时间(2014/10/16 00:00:00),但如果我在日期选择器的文本框中选择日期,它只会显示日期。我不想看时间,怎么了 谢谢 模型中的属性设置如下如何从DatePicker ui jquery中删除时间,jquery,asp.net,asp.net-mvc,jquery-ui,datepicker,Jquery,Asp.net,Asp.net Mvc,Jquery Ui,Datepicker,我正在使用带有asp.net mvc的jquery ui日期选择器,当网页打开时,它会在日期选择器的文本框中显示日期和时间(2014/10/16 00:00:00),但如果我在日期选择器的文本框中选择日期,它只会显示日期。我不想看时间,怎么了 谢谢 模型中的属性设置如下 [DataType(DataType.Date)] [Required(ErrorMessageResourceType = typeof(Ressources.Resources), ErrorMessageResourceN
[DataType(DataType.Date)]
[Required(ErrorMessageResourceType = typeof(Ressources.Resources), ErrorMessageResourceName="ErrorStartDateRequired")]
[Display(Name = "DateStarted", ResourceType = typeof(Ressources.Resources))]
public DateTime DateStarted { get; set; }
我的日期选择器在我的网页中设置如下:
@section scripts{
<script language="javascript" type="text/javascript">
$(document).ready(function () {
var anchor = document.getElementById('@Model.Anchor');
anchor.scrollIntoView(true);
var d = new Date(@Model.Project.DateStarted.Year, @Model.Project.DateStarted.Month, @Model.Project.DateStarted.Day);
$("#datePickerStartDate").datepicker({
dateFormat: "yy/mm/dd",
showOtherMonths: true,
selectOtherMonths: true,
showButtonPanel: true,
changeMonth: true,
changeYear: true,
gotoCurrent: true,
defaultDate: d
});
});
@节脚本{
$(文档).ready(函数(){
var anchor=document.getElementById('@Model.anchor');
anchor.scrollIntoView(true);
var d=新日期(@Model.Project.DateStarted.Year、@Model.Project.DateStarted.Month、@Model.Project.DateStarted.Day);
$(“#datePickerStartDate”).datepicker({
日期格式:“年/月/日”,
showOtherMonths:是的,
选择OtherMonths:true,
showButtonPanel:是的,
变化月:对,
变化年:是的,
gotoCurrent:是的,
默认日期:d
});
});
}
这就是控件在网页(cshtml)中的显示方式
@LabelFor(model=>model.Project.DateStarted,新的{@class=“controllabel col-md-2”})
@Html.TextBoxFor(model=>model.Project.DateStarted,new{id=“datePickerStartDate”})
@Html.ValidationMessageFor(model=>model.Project.DateStarted)
将脚本更改为这种方式,以避免当前日期的时间避免变量d分配
<script>
$("#datePickerStartDate").datepicker(
{
dateFormat: "yy/mm/dd",
showOtherMonths: true,
selectOtherMonths: true,
showButtonPanel: true,
changeMonth: true,
changeYear: true,
gotoCurrent: true,
}).datepicker("setDate", new Date());
</script>
$(“#datePickerStartDate”).datepicker(
{
日期格式:“年/月/日”,
showOtherMonths:是的,
选择OtherMonths:true,
showButtonPanel:是的,
变化月:对,
变化年:是的,
gotoCurrent:是的,
}).datepicker(“setDate”,new Date());
我终于找到了答案。我在视图侧添加了“{0:d}”
<div class="form-group">
@Html.LabelFor(model => model.Project.DateFinished, new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.TextBoxFor(model => model.Project.DateFinished, "{0:d}", new { id = "datePickerEndDate" })
@Html.ValidationMessageFor(model => model.Project.DateFinished)
</div>
</div>
@LabelFor(model=>model.Project.DateFinished,新的{@class=“controllabel col-md-2”})
@Html.TextBoxFor(model=>model.Project.DateFinished,“{0:d}”,new{id=“datePickerEndDate”})
@Html.ValidationMessageFor(model=>model.Project.DateFinished)
谢谢我就是这样用的
@Html.TextBoxFor(a => a.DOB, new { @class = "form-control", placeholder = "Date of Birth", id = "datetimepicker", TextMode = "date", value = "1/11/1989", onkeyup = "return validateChar(this)", maxlength = "20", style = "width:175px;height:25px;" })
<script>
$(document).ready(function () {
$('#datetimepicker').datetimepicker({
lang: 'en',
timepicker: false,
closeOnDateSelect: true,
dateFormat: "yy/mm/dd"
});
});
</script>
@Html.TextBoxFor(a=>a.DOB,新{@class=“form control”,placeholder=“Date of Birth”,id=“datetimepicker”,TextMode=“Date”,value=“1/11/1989”,onkeyup=“return validateChar(this)”,maxlength=“20”,style=“width:175px;height:25px;”)
$(文档).ready(函数(){
$(“#datetimepicker”).datetimepicker({
朗:"嗯",,
计时器选择器:错误,
closeOnDateSelect:true,
日期格式:“年/月/日”
});
});
我不熟悉asp.net语法,但似乎是您在日期选择器中设置的初始值有问题。。。例如,在上面的语法@Html.TextBoxFor(model=>model.Project.DateStarted,new{id=“datePickerStartDate”,value=“pawal”})
中,无论日期选择器的设置如何,它都将值显示为pawal
@Html.TextBoxFor(a => a.DOB, new { @class = "form-control", placeholder = "Date of Birth", id = "datetimepicker", TextMode = "date", value = "1/11/1989", onkeyup = "return validateChar(this)", maxlength = "20", style = "width:175px;height:25px;" })
<script>
$(document).ready(function () {
$('#datetimepicker').datetimepicker({
lang: 'en',
timepicker: false,
closeOnDateSelect: true,
dateFormat: "yy/mm/dd"
});
});
</script>
$("#datePickerStartDate").datepicker({
dateFormat: 'mm/dd/yy',
changeMonth: true,
changeYear: true,
defaultDate: GetCurrentDate(),
onSelect: function () {
$(this).blur().change();
}
});