2010-08-11 198 views
0

我在我的asp.net mvc項目的報告部分使用jquery。但我有jQuery驗證的問題。這裏的代碼不工作,並且在日期時不顯示任何消息輸入文本字段留空。jquery問題:驗證碼不工作

$(document).ready(function() { 
     $("#FromDate").datepicker({ showOn: 'both', buttonText: "select Date", dateFormat: 'M d, yy' }); 
     $("#ToDate").datepicker({ showOn: 'both', buttonText: "select Date", dateFormat: 'M d, yy' }); 
     $("#ParticularDate").datepicker({ showOn: 'both', buttonText: "select Date", dateFormat: 'M d, yy' }); 

     $("#ddlRepoOpt").change(function() { 
      var self = $(this); 
      $("#repoopt").show(); 
      if (self.val() == "") { 
       $("#reop2").hide(); 
       $("#reop1").hide(); 
       $("#reop3").hide(); 
       $("#optionUttOperators").hide(); 
       $("#optionUttTravelAgents").hide(); 
      } 
      else if (self.val() == 1) { 
       $("#reop2").show(); 
       $("#reop1").hide(); 
       $("#reop3").hide(); 
       $("#optionUttOperators").show(); 
       $("#optionUttTravelAgents").show(); 
      } 
      else if (self.val() == 2) { 
       $("#reop1").show(); 
       $("#reop2").hide(); 
       $("#reop3").hide(); 
       $("#optionUttOperators").show(); 
       $("#optionUttTravelAgents").show(); 
      } 
      else { 
       $("#reop1").hide(); 
       $("#reop2").hide(); 
       $("#reop3").show(); 
       $("#optionUttOperators").show(); 
       $("#optionUttTravelAgents").show(); 

      } 
      $("#generateReport").show(); 
     }); 

     **$("#generateReport").live("click", function(e) { 
       var sd = $("#FromDate").val(); 
       var ed = $("#ToDate").val(); 
       var pd = $("ParticularDate").val(); 
      if (sd == "" && ed == "" && pd=="") { 
       alert("Please select the dates"); 
       e.preventDefault(); 
       return false; 
      } 
     }); 

    }); 

我有以下部分的問題。在文本框字段留空時沒有提示消息顯示。

$("#generateReport").live("click", function(e) { 

       var sd = $("#FromDate").val(); 
       var ed = $("#ToDate").val(); 
       var pd = $("ParticularDate").val(); 
      if (sd == "" && ed == "" && pd=="") { 
       alert("Please select the dates"); 
       e.preventDefault(); 
       return false; 
      } 
     }); 

回答

0

試試這個:

$("#generateReport").live("click", function(e) { 
     var sd = $("#FromDate").val(); 
     var ed = $("#ToDate").val(); 
     var pd = $("#ParticularDate").val(); 
     if ((sd == null || sd.length < 1) && (ed == null || ed.length < 1) && (pd == null || pd.length < 1)) { 
      alert("Please select the dates"); 
      e.preventDefault(); 
      return false; 
     } 
    }); 
+0

謝謝...它工作得很好.... – MikMark 2010-08-11 05:04:25

+0

好,這就是爲什麼計算器在這裏... – 2010-08-11 05:04:56