爱易网
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 浏览次数:20198 次
以下是程序代码
<!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
上一篇:狡猾的按钮特效
下一篇:展开层与关闭层的动态缓冲效果特效
免责声明:
本文仅代表作者个人观点,与爱易网无关。其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
相关资料
更多>
欧盟控诉苹果在爱尔兰非法进行税收交易
同为70前后人,马云为什么总是像外星人那么瘦
打车App就是下一个团购骗局!?
富士康欲用机器人产iPhone 6
锐迪科将以9.25美元/ADS价钱出售835万份ADS
特斯拉将获上海免费牌照 充电桩面临双重标准
新闻早8点》Facebook失手发布Snapchat类应用
第二梯队也PK:当1号店“遇上”京东手机节
优酷土豆携手新浪微博 谋攻移动视频失地
推荐阅读
更多>
微信将商场O2O战火烧到了阿里巴巴老家
腾讯微信昨晚再现大规模故障 多地受到影响
杨元庆去年总薪酬1.33亿元
小米打响手机价格战 为米3铺路或另有所图
神奇约炮应用被禁 改名后重返苹果应用商店
诺基亚培育低端机市场 迂回战术要挟中华酷联
华为美国推出电商网站 发售Mate 2LTE版
微博启动自媒体计划 粉丝+收入双激励是亮点
支付宝全面封杀比特币:充值码淘宝店或遭封禁
承载京东C2C野心的拍拍网:梦想丰满,现实骨感
雷军会做赔钱生意?迅雷跌破发行价 市值仅7亿美元
韩国研制无线充电系统:一次可充40部手机
地图导航骤起杀机 百度高德重新定义商业模式
开个房刷个卡全世界都知道个人隐私成公开秘密
HTC曝出特大丑闻:高管诈骗+商业间谍
亚马逊宣布新春大促策略 欲打造另一个"黑五"
火一把就死: 百度魔图验证社交游戏衰亡宿命
弯曲变形:手机全新的交互方式
Facebook以“人”为本的名义占领安卓
历史惊人相似:如今的库克 曾经的鲍尔默