本文介绍了使用java脚本的问题..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我正在使用以下javascript函数来验证日期。 I am using following javascript function to validate date.function IsValidDate(FormName,ElemName, err_display) {var ret = true;var dateStr;if( ElemName != "" ){if( Elem( FormName, ElemName ) == null ) return false;dateStr = Elem( FormName, ElemName ).value;}else{dateStr = FormName;}if (dateStr != ""){var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|[1-9][0-9][0-9][0-9])$/;var matchArray = dateStr.match(datePat); if (matchArray == null) {if( err_display != "" ) {alert(err_display + " is not in a valid format.") FocusElement( FormName, ElemName);}ret = falsereturn false;}month = matchArray[1]; day = matchArray[3];year = matchArray[4];dt = new Date();yearchk = dt.getFullYear();if (month < 1 || month > 12){ if( err_display != "" ) {alert( err_display + ": Month must be between 1 and 12."); FocusElement( FormName, ElemName);}ret = falsereturn false;}if (day < 1 || day > 31) {if( err_display != "" ) {alert( err_display + ": Day must be between 1 and 31."); FocusElement( FormName, ElemName);}ret = falsereturn false;}if ((month==4 || month==6 || month==9 || month==11) && day==31) {if( err_display != "" ) {alert( err_display + ": Month "+month+" doesn't have 31 days.") FocusElement( FormName, ElemName);}ret = falsereturn false}if (month == 2) { var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));if (day>29 || (day==29 && !isleap)) {if( err_display != "" ) {alert( err_display + ": February " + year + " doesn't have " + day + " days."); FocusElement( FormName, ElemName);}ret = falsereturn false;}} if (year <= 1900 && err_display != "") { alert(err_display + ": year must be greater 1900."); FocusElement( FormName, ElemName); ret = false return false }return true;}if( ret == false ){if( err_display != "" ) { alert(err_display + " is not in a valid format.");FocusElement( FormName, ElemName);}else{alert("Date is not in a valid format." ); FocusElement( FormName, ElemName);}return false;}} 问题 这个如果验证单个日期,函数工作正常.. 双文本框出现问题..我有两个文本框和一个按钮.on客户端点击butten事件我调用isValidDate()函数两次下面的文本框.. < asp:按钮ID =btnGetReportrunat =服务器Text =获取报告OnClick =btnGetReport_Click OnClientClick =返回IsValidDate(''aspnetForm'',''ctl00_ContentPlaceHolderBody_txtDateFrom'',''开始日期'');返回IsValidDate(''aspnetForm'',''ctl00_ContentPlaceHolderBody_txtDateTo'',''结束日期''); /> 这里的函数仅检查txtDateFrom文本框而不是txtDateTo文本盒子。如何解决这个问题。我必须使用上面的功能检查单个事件的两个文本框。 i认为由于返回语句而出现问题,cozz first函数返回一些东西并终止。 请帮助.... !! ProblemThis function works fine if validate single date..Problem arise with double text box ..I have two textbox and a button .on client click of butten event i am calling isValidDate() function two times for both text box like below..<asp:Button ID="btnGetReport" runat="Server" Text="Get Report" OnClick="btnGetReport_Click" OnClientClick = "return IsValidDate(''aspnetForm'',''ctl00_ContentPlaceHolderBody_txtDateFrom'', ''Start date'');return IsValidDate(''aspnetForm'',''ctl00_ContentPlaceHolderBody_txtDateTo'', ''End date'');"/>Here function checks only txtDateFrom text box not txtDateTo text box ..How to solve this problem. I have to check both text box on single event by using above function.i think problem arisng due to return statement, cozz first function returns something and terminated.Please help....!!推荐答案 问题 这个如果验证单个日期,函数工作正常.. 双文本框出现问题..我有两个文本框和一个按钮.on客户端点击butten事件我调用isValidDate()函数两次下面的文本框.. < asp:按钮ID =btnGetReportrunat =服务器Text =获取报告OnClick =btnGetReport_Click OnClientClick =返回IsValidDate(''aspnetForm'',''ctl00_ContentPlaceHolderBody_txtDateFrom'',''开始日期'');返回IsValidDate(''aspnetForm'',''ctl00_ContentPlaceHolderBody_txtDateTo'',''结束日期''); /> 这里的函数仅检查txtDateFrom文本框而不是txtDateTo文本盒子。如何解决这个问题。我必须使用上面的功能检查单个事件的两个文本框。 i认为由于返回语句而出现问题,cozz first函数返回一些东西并终止。 请帮助.... !! ProblemThis function works fine if validate single date..Problem arise with double text box ..I have two textbox and a button .on client click of butten event i am calling isValidDate() function two times for both text box like below..<asp:Button ID="btnGetReport" runat="Server" Text="Get Report" OnClick="btnGetReport_Click" OnClientClick = "return IsValidDate(''aspnetForm'',''ctl00_ContentPlaceHolderBody_txtDateFrom'', ''Start date'');return IsValidDate(''aspnetForm'',''ctl00_ContentPlaceHolderBody_txtDateTo'', ''End date'');"/>Here function checks only txtDateFrom text box not txtDateTo text box ..How to solve this problem. I have to check both text box on single event by using above function.i think problem arisng due to return statement, cozz first function returns something and terminated.Please help....!! <asp:Button ID="btnGetReport" runat="Server" Text="Get Report" OnClick="btnGetReport_Click" OnClientClick = "return IsValidDateDateFuncions();/><script>function IsValidDateDateFuncions(){ var TestDate1=return IsValidDate('aspnetForm','ctl00_ContentPlaceHolderBody_txtDateTo', 'End date'); var TestDate2=return IsValidDate('aspnetForm','ctl00_ContentPlaceHolderBody_txtDateFrom', 'Start date')if(TestDate1 && TestDate2){return true;}}</script> <asp:button id="btnGetReport" runat="Server" text="Get Report" onclick="btnGetReport_Click" onclientclick="return CheckValidDates();" xmlns:asp="#unknown" /> function CheckValidDates(){if(IsValidDate('aspnetForm','ctl00_ContentPlaceHolderBody_txtDateFrom', 'Start date') == true && IsValidDate('aspnetForm','ctl00_ContentPlaceHolderBody_txtDateTo', 'End date')== true)return true;elsereturn false;} 这篇关于使用java脚本的问题..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
11-01 04:59