将PHP表单按钮绑定到javascript方法

时间:2014-07-11 07:56:30

标签: php ajax twitter-bootstrap

嗨,大家好我是php的新手,我有一个php表单,如下图所示,它曾经在我使用bootstrap之前工作。

<!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绑定到login.js中的方法

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

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

有什么我想念的吗?

1 个答案:

答案 0 :(得分:0)

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

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

DEMO