2013-01-03 47 views
1

大家好我有登錄表單設計在HTML 5中,並根據登錄細節輸入它shoud重定向到各自的頁面。我正在檢查登錄細節在JavaScript和重定向頁面使用JavaScript,但它不工作。頁面沒有得到重定向。使用javascript重定向html 5表格

<form id="html5form" method="post"> 
      <table border="0" cellpadding="0" cellspacing="0" width="100%" class="tbl_form"> 
       <tbody>       
        <tr> 
         <td> 
          <label>Username: <span>*</span></label> 
         </td> 
         <td> 
          <input type="text" name="txtLoginNm" id="txtLoginNm" class="field" required="required" placeholder="Enter Username" onkeydown="fnAdmPassword(e);"/> 
         </td> 
        </tr> 
        <tr> 
         <td> 
          <label>Password: <span>*</span></label> 
         </td> 
         <td> 
          <input type="password" name="txtPwd" id="txtPwd" maxlength="20" class="field" required="required" Placeholder="Enter Password" onkeydown="fnAdmPassword(e);"/> 
         </td> 
        </tr> 
        <tr> 
         <td> 
          &nbsp; 
         </td> 
         <td> 
          <input type="submit" title="Login" value="Login" name="Login" class="buttom" onclick="javascript:return fnlogin();" /> 
         </td> 
        </tr> 
       </tbody> 
      </table> 
      </form> 

////和JavaScript函數如下

function fnlogin() 
{ 
    if ((document.getElementById("txtLoginNm").value == "") && (document.getElementById("txtPwd").value == "")) 
    { 
     alert("Please enter Username & Password!"); 
    } 
else if ((document.getElementById("txtLoginNm").value == "user155") && (document.getElementById("txtPwd").value == "user155")) 
    { 
     window.location.href = "comp-admin/u_dashboard.shtm"; 
    } 
    else if ((document.getElementById("txtLoginNm").value == "superadmin") && (document.getElementById("txtPwd").value == "superadmin")) { 

     window.location.href = "s-admin/edit-profile.shtm"; 
    } 
else (alert("Invalid username or password!")) 
    } 

請告訴我爲什麼網頁沒有得到重定向

+0

可你也發表您的功能fnAdmPassword(E); –

+0

'onclick =「javascript:return fnlogin();''你必須在這裏刪除'javascript:'部分。 –

回答

0

這就是爲什麼它沒有進行重定向

<input type="submit" title="Login" value="Login" name="Login" class="buttom" onclick="javascript:return fnlogin();" /> 

您必須在這裏做2次更改

  1. 更改按鈕類型,從提交到剛剛按鈕,因爲然後提交的功能正在採取的優先級,你有沒有動作URL定義
  2. 刪除的javascript:從您的通話。 (亦如揚Hančič在評論中所建議的)

那麼試試這個

<input type="button" title="Login" value="Login" name="Login" class="buttom" onclick="return fnlogin();" />