本文介绍了如何为日期格式的TextBox添加反斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 function ValidateDate(txt,keyCode) { if (keyCode == 16 ) isShift = false ; var val = txt.value; var lblmesg = document .getElementById( <%= lblMesg.ClientID%>); if (val.length == 10 ) { var splits = val.split( /); var dt = new 日期(拆分[ 1 ] + / + splits [ 0 ] + / + splits [ 2 ]); // 日期验证 if (dt.getDate()== splits [ 0 ]&& dt.getMonth()+ 1 == splits [ 1 ]&& dt.getFullYear()== splits [ 2 ]) { lblmesg.style.color = green; lblmesg.innerHTML = 有效日期; } else { lblmesg.style.color = red; lblmesg.innerHTML = InValid Date; return ; } // 范围验证 if (txt.id.indexOf( txtRange)!= -1) RangeValidation(dt); // BirthDate验证 if (txt.id.indexOf( txtBirthDate)!= -1) BirthDateValidation(dt)} else if (val.length< 10 ) { lblmesg.style.color = blue; lblmesg.innerHTML = 必需的dd / mm / yy格式。斜杠会自动出现。; } } < asp:TextBox ID = txtValidate runat = server MaxLength = 10 onkeyup = ValidateDate(this,event.keyCode) onkeydown = 返回DateFormat(this,event.keyCode) > < / asp:TextBox > 我想在TextBox中包含一个斜杠来输入Date ..我不希望它在输入时生成斜杠...它加载页面时应该是静态的....是否可以在不使用AjaxToolkit的情况下执行此操作??? 解决方案 尝试 b $ b http://digitalbush.com/projects/masked- input-plugin / [ ^ ] b $ b 对ASP.Net Datecontrol不感兴趣? 日期选择器用户控件 [ ^ ] function ValidateDate(txt, keyCode) { if(keyCode==16) isShift = false; var val=txt.value; var lblmesg = document.getElementById("<%=lblMesg.ClientID%>") ; if(val.length == 10) { var splits = val.split("/"); var dt = new Date(splits[1] + "/" + splits[0] + "/" + splits[2]); //Validation for Dates if(dt.getDate()==splits[0] && dt.getMonth()+1==splits[1] && dt.getFullYear()==splits[2]) { lblmesg.style.color="green"; lblmesg.innerHTML = "Valid Date"; } else { lblmesg.style.color="red"; lblmesg.innerHTML = "InValid Date"; return; } //Range Validation if(txt.id.indexOf("txtRange") != -1) RangeValidation(dt); //BirthDate Validation if(txt.id.indexOf("txtBirthDate") != -1) BirthDateValidation(dt) } else if(val.length < 10) { lblmesg.style.color="blue"; lblmesg.innerHTML = "Required dd/mm/yy format. Slashes will come up automatically."; }} <asp:TextBox ID="txtValidate" runat="server" MaxLength = "10" onkeyup = "ValidateDate(this, event.keyCode)" onkeydown = "return DateFormat(this, event.keyCode)"></asp:TextBox> I want to include a slash within a TextBox for typing a Date.. I don't want it to generate a slash while typing...it should be static when the page is loaded.... Is it possible to do that without using AjaxToolkit ??? 解决方案 tryhttp://digitalbush.com/projects/masked-input-plugin/[^]Not interested in ASP.Net Datecontrol ? Date Picker User Control[^] 这篇关于如何为日期格式的TextBox添加反斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-31 21:39