占位符输入类型日期html5
问题描述:
占位符不直接用于输入类型日期。占位符输入类型日期html5
<input required="" type="text" class="form-control" placeholder="Date"/>
相反,它表明毫米/ DD/YYY
如何显示日期?
答
使用onfocus="(this.type='date')"
,例如:
<input required="" type="text" class="form-control" placeholder="Date" onfocus="(this.type='date')"/>
+0
为什么没有upvote这个解决方案:) – sumit
答
使用的onfocus和的onblur ......这是一个例子:
<input type="text" placeholder="Birth Date" onfocus="(this.type='date')" onblur="if(this.value==''){this.type='text'}">
答
对角2,您可以使用此指令
import {Directive, ElementRef, HostListener} from '@angular/core';
@Directive({
selector: '[appDateClick]'
})
export class DateClickDirective {
@HostListener('focus') onMouseFocus() {
this.el.nativeElement.type = 'date';
setTimeout(()=>{this.el.nativeElement.click()},2);
}
@HostListener('blur') onMouseBlur() {
if(this.el.nativeElement.value == ""){
this.el.nativeElement.type = 'text';
}
}
constructor(private el:ElementRef) { }
}
并像下面一样使用它。
<input appDateClick name="targetDate" placeholder="buton name" type="text">
你可以用css来实现,只有aproach。尝试此:http://*.com/a/34385597/5701302 :) – Yuri
@Elyor编辑:更改类型=“文本”以键入=“日期” –
可能重复的[不显示占位符输入类型=“日期”字段](http://*.com/questions/20321202/not-showing-placeholder-for-input-type-date-field) – Alex