Mobile Input[type=date] When placeholder not work solution

Source: Internet
Author: User

Currently the PC-side support for the date type of input is not good, and the result I tried is only chrome support. Firefox, IE11 are not supported. And there are many calendar controls available on the PC side. You don't have to think about it much.
iOS and Android are supported on the mobile side, but the placeholder property is invalidated when the type is date. PC-side Chrome default display is "Year/month/day", but on the mobile side is a blank.
The date control that comes with the mobile side is really a good thing. Let the user fill in when the experience is very good, very convenient. For the front end, you can omit the verification date format. How can such a good thing be discarded.
The value of input can be set by an attempt, but it must be a date format to be displayed correctly, otherwise it will be ignored directly.

1 <input Type="Date" value="2012-05-10" id="Date">

But when the demand needs to tell the user what to fill out here, it is not enough to be a date alone. The current rejection plan is to combine CSS and JS to solve this problem.

CSS Section

Using pseudo-class to simulate a placeholder for input

1234 input[type= "Date"]:before{ content: attr(placeholder); color:red; }

This is not enough, you will find that after the user has chosen the date we simulated the default text is still in.

JS section

Now that we have used the placeholder attribute, we delete this attribute when the user chooses it, and then add it back if needed.

1234567 var o = document. getElementById(' Date '); o. onfocus = function(){ This . RemoveAttribute(' placeholder '); };o. onblur = function(){ If(this. Value = = ") this . SetAttribute(' placeholder ',' I am the date '); };

By the way, input of non-date type set placeholder color CSS

123 ::-webkit-input-placeholder { color:red; }

Mobile Input[type=date] When placeholder not work solution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.