HTML:在输入类型日期中首先显示占位符

时间:2016-06-11 05:41:09

标签: html css

我可以先在输入中显示占位符吗?现在,当我点击输入框时,我可以看到占位符,但我想要它,这样当我加载页面时,占位符已经可以立即读取。

而不是mm / dd / yyyy,它应该显示加载页面时的出生日期1

谢谢!

4 个答案:

答案 0 :(得分:4)



db.Comapnies.Include(c => c.Teams
                           .Select(t => t.ApplicationUserTeam
                                         .Select(aut => aut.AspNetUsers)));




阅读本页

How do I simulate placeholder functionality on input date field?

答案 1 :(得分:1)

        var dateofbirth="01/23/1990";
        document.getElementById('test').placeholder=dateofbirth;

codepen- http://codepen.io/nagasai/pen/OXMdvr

答案 2 :(得分:1)

您可以将输入日期默认占位符与 :before 元素重叠。 必须用onChange事件

控制输入元素

/* When Input type="date" && value="" => hide Input content */

input[type="date"][value=""] {
  position: relative;
  height: 100%;
  color: transparent;
  transition: all 0.2s;
}


/* When focus show it*/

input[type="date"]:focus {
  color: inherit;
}


/* Input type="date" && value="" => overlap with before */

input[type="date"][value=""]:before {
  content: attr(placeholder);
  position: absolute;
  height: 100%;
  width: calc(100% - 20px);
  padding-top: 4px;
  color: #aaa;
  background-color: white;
  transition: all 0.2s;
}


/* rid off before on focus */

input[type="date"]:focus:before {
  content: none;
}
<input type="date" placeholder="My placeholder" value="" />

答案 3 :(得分:0)

http://www.htctu.net/html5/forms/formInputTypes.html#date 试试这个链接。

<input type=date form="sf1" name="date" placeholder="23-7-1988">