爱易网
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 浏览次数:20175 次
以下是程序代码
<!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
上一篇:狡猾的按钮特效
下一篇:展开层与关闭层的动态缓冲效果特效
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
美国政府关门可能影响去哪儿等公司IPO
韩国研制无线充电系统:一次可充40部手机
京东联席董事长赵国庆上市前夕离职
Android版WhatsApp曝漏洞:聊天记录可被窃取
传苹果已告知鸿海:两款新iPhone下月发货
Line风靡亚洲,在北美却进展缓慢
去看看外面的世界吧!别窝里斗了,中国在线旅游商们
HTC以品牌营销突围 专家建议改变经营思路
北京今日实现用支付宝钱包为公交卡充值
推荐阅读
更多>
只有切到刚需痛点,漫画APP才能走下去
虚拟运营市场躁动:山西煤老板兴味浓重
魅族黄章惹怒芙蓉姐姐 将跨界推女神手机
传搜狗估值12亿美元 与360谈判进入白热化
中移动推动感地带3G网聊卡 火拼微信沃卡
组建铁塔公司倒逼运营商改革 或加速4G网建设
微软确认 Surface 计划更多尺寸和LTE 版本
八位知名设计师评iOS7:新鲜但复杂
美国电影协会在华起诉迅雷侵权 要求赔偿并道歉
任正非:华为决不上市 上市公司股东贪婪而短视
国网公司将加快组建 业界人士称困难重重
曹国伟:微博将关注Facebook和Twitter
华为坚持不上市究竟为何?不差钱也不想冒风险
不提老罗,不说情怀,仅从十四个投诉问题入手谈锤子手机
苹果6月20日发布iPhone5S 触摸屏概念股生动
FB上广告费用昂贵而且效果不及Twitter
优酷土豆携手新浪微博 谋攻移动视频失地
阿里马云:我觉得互联网还有十年可以做
摩托罗拉移动裁员关闭德州Moto X手机工厂
京东进驻微信一级入口或影响自身战略布局