最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Date Auto format with javaScript - Stack Overflow

programmeradmin4浏览0评论

how to make date Auto Format in input textbox with javascript

when input yyyyMMdd format in textbox, that will automatically change to yyyy/MM/dd format

for example: if your type 20120427, that will change to 2012/04/27

how to make date Auto Format in input textbox with javascript

when input yyyyMMdd format in textbox, that will automatically change to yyyy/MM/dd format

for example: if your type 20120427, that will change to 2012/04/27

Share Improve this question asked Apr 27, 2012 at 7:29 emeraldemerald 3294 gold badges5 silver badges10 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

you can try this javaScript Function and Call it from onChange event of your textbox

function dateFormat(el){
    value = el.value;       
    el.value = value.replace(/^([\d]{4})([\d]{2})([\d]{2})$/,"$1/$2/$3");        
}

First, you need to write a function to do the convert,

function convert(original){};

then listen to onkeyup evnets, and pass the value of the input to the convert function, set the input's value to its result

发布评论

评论列表(0)

  1. 暂无评论