爱易网
IT新闻
IT新闻
爱易资讯
网站搭建
云虚拟主机教程
云服务器教程
Apache教程
IIS教程
Nginx教程
网站策划
站长文章
推广教程
淘宝客教程
网页设计
HTML教程
XHTML教程
CSS教程
HTML5教程
CSS3教程
JavaSript基础
JQuery教程
Node.js教程
前端技术
Ajax教程
Js特效
Xml教程
平面设计
页面UI设计
photoshop教程
程序开发
AI人工智能
Asp教程
Php教程
Asp.Net教程
Net Core教程
C#教程
Java教程
Jsp教程
开发技术
微信小程序教程
Uniapp开发教程
微信公众号开发
Andriod教程
IOS教程
DOS教程
Python教程
Docker教程
Windows Container教程
数据库
MSSQL教程
MySQL教程
Redis教程
Access教程
Oracle教程
数据库教程
操作系统
Linux教程
Windows教程
MAC教程
Cisco教程
交换机教程
防火墙教程
搜索
爱易网页
JS特效
有提示的输入框日期格式
有提示的输入框日期格式
日期:2014-05-18 浏览次数:20217 次
以下是程序代码
<!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" /> <TITLE> 日期格式限制 ali_xixi.com整理收集 </TITLE> <style> input{font-size:12px;} </style> <script type="text/javascript"> /* *** http://www.hansir.cn *** */ var date_help = function(inp, divide){ this.inp = document.getElementById(inp); this.divide = divide; this.format = 'YYYY'+divide+'MM'+divide+'DD'; //显示字符样式 this.styleH='<span style="font-weight:bold; color:green">'; this.styleB='</span>'; this.load(); // 初始化 } date_help.prototype={ load: function(){ // 创建一个用于显示提示的DIV并设置样式 var div = document.createElement('div'); div.setAttribute('style', 'height:21px; line-height:21px;font-family:宋体; font-size:13px; letter-spacing:1px; text-align:center; background:#fffff6; color:#f60; border:1px solid #ccc; border-top:0; position:absolute; visibility:hidden'); div.style.cssText = 'height:21px; line-height:21px; font-family:宋体; font-size:13px; letter-spacing:1px; text-align:center; background:#fffff6; color:#f60; border:1px solid #ccc; border-top:0; position:absolute; visibility:hidden'; div.innerHTML = this.format; this.div = div; document.body.appendChild(div); // 设置DIV的位置 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'; // 加载输入框事件 var oThis = this; this.inp.onfocus = function(){ oThis.inp_v.call(oThis); } this.inp.onblur = function(){ oThis.inp_h.call(oThis); } this.inp.onkeypress = function(e){ //键盘按下事件 e?intKey=e.which:intKey=event.keyCode; return oThis.inp_press.call(oThis, intKey); } this.inp.onkeyup = function(e){ e?intKey=e.which:intKey=event.keyCode; oThis.inp_chk.call(oThis,intKey); } }, inp_v: function(){ // 提示信息显示 this.div.style.visibility = 'visible'; }, inp_h: function(){ // 提示信息显示 if(new RegExp('^\\d+'+this.divide+'\\d'+this.divide).test(this.inp.value)){ // 月数补0 this.inp.value = this.inp.value.replace(new RegExp('^(\\d+'+this.divide+')(\\d)(?='+this.divide+')'),'$10$2'); this.parseDate(); this.parseFormat(); } if(new RegExp('^\\d+'+this.divide+'\\d+'+this.divide+'\\d$').test(this.inp.value)){ // 天数补0 this.inp.value = this.inp.value.replace(/(\d)$/,'0$1'); this.parseDate(); this.parseFormat(); } this.div.style.visibility = 'hidden'; }, inp_press: function(intKey){ //键键按下事件 只接受数字和分隔符 return (new RegExp('[\\d'+this.divide+']').test(String.fromCharCode(intKey)) || (intKey==0||intKey==8)); }, inp_chk: function(intkey){ // 格式化日期及提示信息样式 if(intKey==37||intKey==39)return; // 左右键不检测 this.parseDate(intKey); // 格式化日期 this.parseFormat(); // 格式化提示信息 }, parseDate: function(intKey){ // 格式化日期 var intDate = this.inp.value.replace(/\s/g,''); var divide=this.divide; var strDateArray = intDate.split(divide); strDateArray[0]?intYear = strDateArray[0].replace(/^(\d*).*$/,'$1'):intYear=''; strDateArray[1]?intMonth = strDat
上一篇:狡猾的按钮特效
下一篇:展开层与关闭层的动态缓冲效果特效
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
湘鄂情剥离餐饮业务进军大数据的底气在哪里?
金山毒霸安全中心: XP退役后首个高危漏洞来了
如家撤离同程内情:祸起反水OTA“联盟”?
“世界杯+618”集体磨刀的本质是绑架全民
CSS控制字符长度和显示长度
诺基亚因充电器问题暂停销售Lumia 2520平板电脑
支付宝27日晚间曝严重破绽:买卖记载可被搜索
微软提示XP只剩365天寿命:用户被绑架?
传苹果已告知鸿海:两款新iPhone下月发货
推荐阅读
更多>
刘强东向总理建言:打击有组织有规模的售假商家
微信企业号必须搬走四座大山,否则只能铩羽而归!
2018年阿里云双11活动如何参加?1折优惠大攻略
阿里巴巴450亿勾画“现代服务业”藏宝图
国美苏宁线上首度正面PK 京东列席4月电商战
微软确认 Surface 计划更多尺寸和LTE 版本
阿里收购UC 五年姻缘换来移动新格局
苹果联合创始人炮轰鲍尔默“一直都在吃老本”
苏宁易购成世界最慢电商 专家称其涉嫌违约
黑狐病毒疯传播 电脑管家首推 专杀工具
互联网金融一周年:余额宝最接地气,比特币最作死
途牛旅游网今晚挂牌纳斯达克 融资1亿美元
AMD Q1净亏1.46亿美元 转战SOC拥抱ARM求变
小米移动芯片:英伟达退出,终会加强与联发科合作
从旗下三大业务BG发展看华为的过去现在和未来
锐迪科将以9.25美元/ADS价钱出售835万份ADS
谁说黑莓没救?他们在悄悄地深耕企业级市场,在这个领域,苹果三星算什么,他们远远不是黑莓的对手
华为、小米和联想在中国手机市场上演“三国杀”
高通反垄断案下月有望落定
湘鄂情剥离餐饮业务进军大数据的底气在哪里?