2014-07-11 19 views
0

嗨,我是新来的php,我有一个如下所示的php表单,它在我应用bootstrap之前工作。将PHP表单按钮绑定到javascript方法

<!doctype html> 
    <html lang="en"> 
    <head> 
     <meta charset="UTF-8"> 
     <title> Login Page</title> 
     <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
     <link type="text/css" href="css/login.css" rel="stylesheet" /> 
     <link type="text/css" href="css/bootstrap/bootstrap.min.css" rel="stylesheet" media="screen">  
    </head> 
    <body> 
     <!-- Main Container --> 
      <div class="container"> 
       <div class="row"> 
        <div class="col-sm-6 col-md-4 col-md-offset-4"> 
         <h1 class="text-center login-title">Sign in to HRMS</h1> 
         <div class="account-wall"> 
          <img class="profile-img" src="https://lh5.googleusercontent.com/-b0-k99FZlyE/AAAAAAAAAAI/AAAAAAAAAAA/eu7opA4byxI/photo.jpg?sz=120" 
           alt=""> 
          <form class="form-signin" method="post" action=""> 
           <input type="text" id="txtEmpID" class="form-control" placeholder="Employee ID" required autofocus> 
           <input type="password" id="txtEmpPass" class="form-control" placeholder="Password" required> 
           <button id="btnLogin" class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button> 
          </form> 
         </div>     
        </div> 
       </div> 
      </div> 
     <script type="text/javascript"> 
      var login_url = "<?php echo Util::convertLink("Login") ; ?>" ; 
      <?php include (PATH_CODE . "js/general/login.min.js") ; ?> 
     </script> 
    </body> 
</html> 

与按钮登录绑定到login.js

$(document).ready(function() 
{ 
    $('#btnLogin').button().bind('click',this,onLogin) ; 
}) ; 

function onLogin(obj) {    
    alert($('#txtEmpID').val()); 
} 

它有我丢失的东西的方法?

+2

首先,VAR LOGIN_URL = “”;尝试使用$('#btnLogin')。click(function(){alert($('#txtEmpID')。val()); return false;}); –

+0

看起来你的表单没有动作=“” - >所以当你提交时,它什么都不做。将它指向您的登录脚本以解析formdata中的信息。 –

+0

它有什么作用?它警觉吗?你有没有包含jQuery? – putvande

回答

0
$(document).ready(function() 
{ 
    $('#btnLogin').bind({ 
     click: function() { 
     onLogin(this); 
     } 
    }); 
}); 

function onLogin(obj) {    
    alert($('#txtEmpID').val()); 
} 

DEMO