javascript - 如何添加占位符 <input type ="datetime-local"> 字段?

标签 javascript css html forms

我一直在尝试在 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 - 如何添加占位符 &lt;input type ="datetime-local"> 字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30048323/

相关文章:

javascript - 如何在表格中找到最后一个可见的 <td>?

javascript - jQuery 克隆元素并避免采用父节点

javascript - 在 html 或 JS 中有没有一种方法,当我将鼠标悬停在某些东西上时它会改变?

javascript - 在同一域的 iframe 之间共享对象

javascript - 在主要 "meat"仍然是服务器端的 webapps 中组织 JS 代码的最佳方式是什么?

jquery - 为什么这个用于使 div 转到右上角或左上角的 jQuery 代码不起作用?

html - 如何在odoo报告中添加一个字段?

javascript - 检测 Javascript 事件类型

javascript - 创建没有任何父级的树结构作为一级对象列表的输入

jquery - 有问题的 JQuery .animation()