Input type date solves the problem of mobile terminal display placeholder, inputplaceholder

Source: Internet
Author: User

Input type date solves the problem of mobile terminal display placeholder, inputplaceholder

 

In a recent project, a new tag attribute of html5 is used. When type = "date" is used, it is found that the placeholder attribute is invalid and cannot be used.

If this is the case, the customer experience is unimaginable.

Finally, I thought about how to fix it with css + js double insurance.

Method 1:

Css:

Input [type = "date"]: before {content: attr (placeholder); // force the placeholder attribute color: # aaa; // This gray color should be the most suitable}

This step does not work, because after the input box has a value, the placeholder still cannot be hidden.

Now js is on the stage.

<Input type = "date" name = "birthday" id = "birthday" class = "txt1" datatype = "*" nullmsg = "set the date of birth! "Placeholder =" Please set the date of birth! "Onfocus =" this. removeAttribute ('placeholder ') ">
Method 2:

Css:

input[type="date"]:before{    color:#A9A9A9;    content:attr(placeholder);}input[type="date"].full:before {    color:black;    content:""!important;}

Js:

$("#date").on("input",function(){   if($(this).val().length>0){   $(this).addClass("full");}else{  $(this).removeClass("full");  } });

Html:

<Input id = "date" class = "weui_input" type = "date" placeholder = "select the date of Birth" style = "height: 41px; overflow: hidden;">

If the input height is not set, both placeholder and date will be displayed and two rows will be displayed under Android. You can solve this problem by adding overflow to the height limit.

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.