当用户点击输入框准备输入后显示一个日期输入格式样本在旁边,提醒用户按照格式输入,结合自己的需求来修改即可。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <meta name="keywords" content="武鸣人网站,武鸣信息网,武鸣本地网,武鸣信息资源平台,减肥,健身,励志,励志语录,js特效,网页特效,www.wuming.ren"> <meta name="description" content="欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。"> <TITLE>输入框日期提示,武鸣人欢迎您。</TITLE> <style> fieldset{ width:300px; padding:20px;} </style> <script type="text/javascript"> var data_help = function(inp, format){ this.inp = document.getElementById(inp); this.format = format; var div = document.createElement('div'); div.setAttribute('style', 'height:21px; font-size:12px; line-height:21px; background:#fffff6; color:#f33; border:1px solid #ccc; border-top:0; text-indent:3px; position:absolute; visibility:hidden'); div.style.cssText = 'height:21px; line-height:21px;font-size:12px; background:#fffff6; color:#f33; border:1px solid #ccc; border-top:0; text-indent:3px; position:absolute; visibility:hidden'; div.innerHTML = this.format; this.div = div; document.body.appendChild(div); this.load(); var oThis = this; this.inp.onfocus = function(){ oThis.inp_v.call(oThis); } this.inp.onblur = function(){ oThis.inp_h.call(oThis); } this.inp.onkeyup = function(){ oThis.inp_chk.call(oThis); } }//武鸣人网站https://www.wuming.ren 网站很好记住,wuming.ren(武鸣拼音.ren域名后缀) data_help.prototype={ load: function(){ var inp = this.inp; var inpW = inp.offsetWidth, inpH = inp.offsetHeight; var left = 0, top = 0; while(inp != null){ left += inp.offsetLeft; top += inp.offsetTop; inp = inp.offsetParent; } this.div.style.height = '21px'; this.div.style.width = inpW-2 + 'px'; this.div.style.left = left + 'px'; this.div.style.top = inpH+top + 'px'; }, inp_v: function(){ this.div.style.visibility = 'visible'; }, inp_h: function(){ this.div.style.visibility = 'hidden'; }, inp_chk: function(){ var p = this.inp.value.replace(/\s/g,''); var w = this.format; var n=0; for(var i=0; i<p.length; i++){ if(/[^a-zA-Z]/.test(w.charAt(i))){ if(p.charAt(i)!=w.charAt(i)){ break; } } n++; } this.div.innerHTML= '<span style="font-weight:bold; color:green">'+w.slice(0,n)+'</span>'+w.slice(n,w.length); } } window.onload = function(){ new data_help('birthday', 'yyyy/mm/dd'); new data_help('birthday2', 'yyyy-mm-dd'); } </script> </HEAD> <body> <a href="https://www.wuming.ren">武鸣人</a>,各种信息资源免费发布,分享励志语录经典短句,减肥健身常识,各种js特效代码。网站很好记住,wuming.ren(武鸣拼音.ren域名后缀)<hr> <!--欢迎来到武鸣人信息资源平台,各种信息免费发布,资源共享合作共赢,分享互联网流行的励志语录经典短句,减肥健身健康小常识及打卡记录,收集各种js特效代码。--> <script type="text/javascript" src="https://www.wuming.ren/ad/tc.js"></script> <script type="text/javascript" src="https://www.wuming.ren/ad/a.js"></script> <div> 武鸣人一号:<input type="text" id="birthday" /><br/><br /><br /> 武鸣人二号:<input type="text" id="birthday2" /><br/><br /><br /> </div> </body> </html>
本文来自武鸣人网站,转载请注明出处