jQuery 从 chrome 中的日期类型输入中删除占位符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25018653/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove placeholder from date type input in chrome
提问by Elad Lachmi
I have the following input:
我有以下输入:
<input class="AccordionLeft" id="operationDate" name="OperationDate" type="date" value="">
This shows the date format as a default placeholder. I would like to remove this placeholder and just have an empty input field.
这将日期格式显示为默认占位符。我想删除这个占位符,只有一个空的输入字段。
If I do this:
如果我这样做:
`$('#operationDate').val('@DateTime.Now.ToString("yyyy-MM-dd")');`
I get today`s date as the placeholder, but if I use this:
我得到今天的日期作为占位符,但如果我使用这个:
$('#operationDate').val('');
I get the placeholder like dd-mm-yyyy
.
Can the placeholder be removed entirly? I have seen several posts about changing the date format, but have found none about removing the placeholder completley.
我得到像dd-mm-yyyy
. 占位符可以完全删除吗?我看过几篇关于更改日期格式的帖子,但没有发现关于完全删除占位符的帖子。
回答by Jeroen Bellemans
You could achieve a nice effect using onfocus
and onfocusout
, along with some CSS.
您可以使用onfocus
和onfocusout
以及一些 CSS来获得不错的效果。
<input name="date" type="text" onfocus="(this.type='date')" onfocusout="(this.type='text')">
回答by int32_t
You can hide the format placeholder with the following style rule:
您可以使用以下样式规则隐藏格式占位符:
<style>
::-webkit-datetime-edit-year-field:not([aria-valuenow]),
::-webkit-datetime-edit-month-field:not([aria-valuenow]),
::-webkit-datetime-edit-day-field:not([aria-valuenow]) {
color: transparent;
}
</style>
<input type=date>