我一直在尝试在 input type='datetime-local' 字段中添加占位符,但它根本不起作用。用css解决问题还是不行:(
input[type="datetime-local"]:before{
content: 'Selecteer Datum';
color: #000;
text-align: center;
width:100%;
}
input[type="datetime-local"]:active:before, input[type="datetime-local"]:hover:before, input[type="datetime-local"]:visited:before, input[type="datetime-local"]:focus:before{
content: '';
width: 100%;
}
<form action="" method="post">
<div class="datetime">
<input type="datetime-local" >
</div>
</form>
最佳答案
这是一个奇怪的想法,将输入类型更改为 text
,然后它将使用以下 javascript 转换为焦点上的 datetime-local
。
<input type="text" id="txtbox" placeholder="Heya">
<script>
var dtt = document.getElementById('txtbox')
dtt.onfocus = function (event) {
this.type = 'datetime-local';
this.focus();
}
</script>
关于javascript - 如何添加占位符 <input type ="datetime-local"> 字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30048323/