日期字段不会在Chrome浏览器中显示该值 [英] Date field does not display the value in Chrome browser

查看:160
本文介绍了日期字段不会在Chrome浏览器中显示该值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我的剃刀视图定义如下

 < input id =date1type =textclass =requiredvalue =@ Model.Date.ToShortDateString()maxlength =10/> 

< input id =date2type =dateclass =requiredvalue =@ Model.Date.ToShortDateString()maxlength =10/>

我在Chrome下运行它,第一个输入显示正确的日期值。
第二个输入仅显示mm / dd / yyyy,即使点击向下箭头时的日历显示。



我想要第二个输入字段显示值而不是mm / dd / yyyy

解决方案

当您在HTML5中使用新的< input type =date... 时,您需要传递ISO中的值格式,它是 yyyy-MM-dd 。因此,将您的标记更改为:

 < input id =date2type =dateclass =requiredvalue = @ Model.Date.ToString(yyyy-MM-dd)maxlength =10/> 


I am having problem binding date value in Chrome browser.

My razor view defined as follow

<input id="date1" type="text" class="required" value="@Model.Date.ToShortDateString()"  maxlength="10" />

<input id="date2" type="date" class="required" value="@Model.Date.ToShortDateString()"  maxlength="10" />

I ran it under Chrome, the first input display the date value correct. the second input only display mm/dd/yyyy even though a calendar display when I click on the down arrow.

I would like to have the second input field to show the value instead of mm/dd/yyyy

解决方案

When you use the new <input type="date" ... in HTML5, you need to pass the value in ISO format, which is yyyy-MM-dd. So change your markup to:

<input id="date2" type="date" class="required" value="@Model.Date.ToString("yyyy-MM-dd")"  maxlength="10" />

这篇关于日期字段不会在Chrome浏览器中显示该值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆