2014-10-18 100 views
0

现在!isValid不接受任何当前余额的输入值。是否有另一种方法来验证输入中的值? JSFiddle!isValid不接受来自输入的任何值

有问题的功能:

function isValid(entry, a, b) 

     { 
      if (isNaN(entry.value) || (entry.value==null) || (entry.value=="") || (entry.value < a) || (entry.value > b)) { 
      alert("Invalid entry. Your min payment should be between " + a + " and " + b + ".") 
       return false 
      } 
       return true 
     } 


    // send entries to validation function 
    // exit if not valid 
     if (!isValid(currentBalance, 0, 10000)) { 
      return false 
     } else if (!isValid(interest, 0, 30)) { 
      return false 
     } else { 
      return true; 
     } 

     if (!isValid(mnth_pay, currentBalance*.02, currentBalance)) { 
      return false 
     } else { 
      console.log("do nothing"); 
    } 

回答

0

我刚刚调整您的Fiddle。 当我第一次添加console.msg以获取由函数isValid(entry,a,b)处理的值时,我注意到entry.value未定义,但条目与当前输入匹配。
调整到

function isValid(entry, a, b) 
    { 
     if (isNaN(entry) || (entry==null) || (entry=="") || (entry < a) 
     || (entry.value > b)) 
     {... } 
    } 

似乎解决这个问题。