2016-07-30 48 views
-2

我有兩個文本框命名txtA,txtB簡單如果別人無法獲得工作

var count;//which needs to be compared with BValue 
var AValue = $("#txtA").val(); 
var BValue = $("#txtB").val(); 

if (AValue == "") { 
      alert("Enter AValue and continue"); 
     } else if (BValue == "") { 
      alert("Enter To BValue and continue"); 
     } else if (AValue > BValue) { 
      alert("AValue should be lesser than To BValue"); 
     } else if (AValue == "" || BValue == "") { 
      alert("Please enter the AValue and BValue to continue"); 
     } else if (AValue == "0") { 
      alert("Invalid AValue"); 
     } else if (BValue > count) { 
      alert("Invalid BValue"); 
     } else { 
      // do some operations here 
     } 

所有條件都經過良好,但這種BValue > count被觸發我雖然滿足條件

+0

我想你忘了關括號。因此:if($(「Value ==」)) – 2016-07-30 04:51:41

+0

if($(「AValue ==」)「if not(AValue == ==」)我在OP – guradio

+0

語法錯誤中看不到'BValue> 「」) –

回答

0

檢查該工作示例。

<!DOCTYPE html> 
<html lang="en"> 
    <head> 
     <title>Example</title> 
     <meta charset="utf-8"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script> 
    </head> 
    <body> 
    <input type="text" id="txtA" name="txtA"> 
    <input type="text" id="txtB" name="txtB"> 

    <button onclick="CheckVal()" type="button"> Check It </button> 

     <script type="text/javascript"> 
      function CheckVal(){ 

       var count;//which needs to be compared with BValue 
       var AValue = $("#txtA").val(); 
       var BValue = $("#txtB").val(); 

       if (AValue == "") { 
          alert("Enter AValue and continue"); 
         } else if (BValue == "") { 
          alert("Enter To BValue and continue"); 
         } else if (AValue > BValue) { 
          alert("AValue should be lesser than To BValue"); 
         } else if (AValue == "" || BValue == "") { 
          alert("Please enter the AValue and BValue to continue"); 
         } else if (AValue == "0") { 
          alert("Invalid AValue"); 
         } else if (BValue > count) { 
          alert("Invalid To Page Number"); 
         } else { 
          // do some operations here 
          alert("This is Else Part"); 
         } 
       } 
     </script> 

    </body> 
</html> 
1

要麼使用:

if (AValue == ""){ 

} 

或者

if (($("#txtA").val()) == ""){ 

}