当前位置: 动力学知识库 > 问答 > 编程问答 >

javascript - date format of textfield using java script and php

问题描述:

i am making a form that has a date field using textfield, i want my date field to have a label format inside the textfield, here's the picture:

after clicking on the textfield the format will be erased and the hyphen will remain like this picture:

i already made the code for the label format,

here's my code:

<input type="text" name="date" value="DD_MM_YYYY" id="date" style="width:180px" onclick="if(this.value=='DD_MM_YYYY'){this.value=''}" />

</p>

My problem now is the hypen that will remain after clicking the textfield.

Anyone knows how to do that?

Thanks in advance.

网友答案:

I would recommend Masked Input Plugin.
http://digitalbush.com/projects/masked-input-plugin/

You can define your own type of mask by using the code:

jQuery(function($){
   $("#myinput").mask("99-99-9999",{placeholder:" "});
});

Then you can define a placeholder to the input:

<input id='myinput' placeholder='dd-mm-yyyy'>
网友答案:

You can use the placeholder attribute.

<input placeholder="  -  -    " value="DD-MM-YYYY" />

You can continue to set the value to nothing when the element is focused. On blur set the value back to DD-MM-YYYY.

Note that this attribute isn't supported by all browsers.

分享给朋友:
您可能感兴趣的文章:
随机阅读: