使用javascript外部文件提交表单

时间:2014-03-24 12:40:18

标签: javascript forms

我有这个登录页面:

<html>
    <head>
        <title>TODO supply a title</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width">
        <link rel="stylesheet" type="text/css" href="css/bootstrap.css" media="screen" />
        <script src="http://code.jquery.com/jquery.js"></script>
        <script type="text/javascript" src="js/loader.js"></script>
    </head>
    <body>
        <div id ="header_login"></div>
        <div id ="fdm_intro"></div>
        <div id="footer"></div>
    </body>
</html>

和休息标题:

<html>
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width">
        <link rel="stylesheet" type="text/css" href="css/bootstrap.css" media="screen" />
        <script type="text/javascript" src="login.js"></script>
        <script src="login.js"></script>
    </head>
    <body>
        <div id ="header">
            <div class="navbar">
                <div class="navbar-inner">
                    <a class="brand" href="#"> Flight Data Monitor</a>
                    <form name="login" action="" method="GET" class="navbar-form pull-right">
                        <input type="text" class="span2" placeholder="Username" name="username">
                        <input type="text" class="span2" placeholder="Password" name="password">
                        <button type="submit" class="btn" onclick="login(this.form);" >Entrar</button>
                    </form>
                </div>
            </div>
        </div>
    </body>
</html>

问题:我无法在login.js中发出警报。好像我的表单没有调用javascript ....任何帮助??

1 个答案:

答案 0 :(得分:0)

您忘记在html页面中添加Jquery引用。试试这段代码。

<html>
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width">
    <link rel="stylesheet" type="text/css" href="css/bootstrap.css" media="screen" />
    <script src="http://code.jquery.com/jquery-1.9.1.js"></script>      
    <script src="login.js"></script>
    </head>
    <body>
    <div id ="header">
        <div class="navbar">
            <div class="navbar-inner">
                <a class="brand" href="#"> Flight Data Monitor</a>
                <form name="login" action="" method="GET" class="navbar-form pull-right">
                    <input type="text" class="span2" placeholder="Username" name="username">
                    <input type="text" class="span2" placeholder="Password" name="password">
                    <button type="submit" class="btn" onclick="login(this.form);" >Entrar</button>
                </form>
            </div>
        </div>
    </div>
    </body>
</html>

<强> Login.js:

$(document).ready(function() {
     alert();       
});