2016-04-17 45 views
-1

無法通過驗證我的提交按鈕路由到此HTML頁面... 罪魁禍首-----------------> return true; window.location.href =「Info/index.html」;返回true; NOT路由到鏈接

function validate() 
     { 

     if(document.myLogIn.user_id.value == "") 
     { 
      alert("Please provide your Customer ID!"); 
      document.myLogIn.user_id.focus() ; 
      return false; 
     } 

     if(document.myLogIn.password.value == "") 
     { 
      alert("Please provide your Password!"); 
      document.myLogIn.password.focus() ; 
      return false; 
     } 
      return true; window.location.href= "Info/index.html"; 
     } 
+0

你試過把'window.location.href =「Info/index.html」';返回聲明之前? –

+0

是的,遺憾的是沒有工作... –

回答

1

原因:代碼無法訪問。

在您的代碼:

window.location.href= "Info/index.html"; 

將不會被執行,因爲你已經設置了 'return' 語句。

不知道到底是什麼你最多,但你可以設置你這樣的代碼來代替:

window.location.href= "Info/index.html"; 
return true; 

所以你設置返回值爲true之前您重定向將被執行。

祝你好運!

+0

沒有這樣的運氣 - 對客戶ID運行驗證功能,並且如果字段在點擊提交時填入,他們被重新路由到另一頁... –

+0

問題解決了! –

+0

window.location.href =「Info/index.html」; 返回false; –