jQuery可以在Firebug控制台上运行,但不能在页面加载时运行

时间:2010-10-08 06:41:58

标签: jquery firebug

我对jQuery和javascript很新,所以也许我错过了一些东西。

我有一个html页面,其中包含最新版jQuery的链接...

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

但是我尝试在头部或单独的.js文件中执行的任何jQuery代码在我加载页面时都不会运行。不过普通的javascript确实如此。

Firebug承认,当我点击Script或Dom时,jQuery库已经加载了...控制台甚至会毫不费力地接受并运行我的jQuery代码。

这是html ...是的,它是html5,除了Opera和IE之外,它在所有浏览器中运行良好。

<!DOCTYPE HTML>
<html>
    <head>
        <title>Produkshunator</title>   

        <link rel="stylesheet" type="text/css" href="styles/layout.css" />
        <link rel="stylesheet" type="text/css" href="styles/skins.css" />
        <link rel="stylesheet" type="text/css" href="styles/formlayout.css" />  
        <link rel="stylesheet" type="text/css" href="styles/index.css" />

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>  
        <script type="text/javascript" src="scripts/json2.min.js"></script>
        <script type="text/javascript" src="index4.js"></script>

    </head>

    <body class="vbox flex">

      <!-- header ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

        <header class="hbox">
            <div class="hbox flex" style="padding-top: 5px;">
                <img src="icons/Produkshunator.png" style="height:60px;width:490px;"/>
            </div>
            <div id="login_status" style="width:150px;"></div>  
        </header>

      <!-- body ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->

        <div class="flex hbox">



<!-- Forms ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->              

                <section class="vbox right" style="width:400px; padding:0; overflow: visible;">

    <!-- Login Form ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~-->

                <form class="flex sleek"
                      name="login"
                      id="login">

                    <h2 class="r">Login</h2>

                    <div>   
                        <label>Email:</label>
                        <input type="email" name="email"/>
                     </div>
                     <div>
                        <label>Password:</label>
                        <input type="password" name="password"/>
                     </div>
                     <div>                       
                         <input type="button" value="Submit" class="form_butt" />
                     </div>
                     <p><i id="log_error" class="error"></i></p>    
                </form>


    <!-- Registration Form ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->   

                <form class="sleek flex"
                      name="register"
                      id="register">
                    <h2 class="r">Register</h2>

                      <div>
                         <label>First Name:</label>
                         <input type="text" required="flag" name="firstname"/>
                      </div>
                      <div>
                         <label>Last Name:</label>
                         <input type="text" required="flag" name="lastname"/>
                      </div>
                      <div>
                         <label>Email:</label>
                         <input type="email" required="flag" name="email"/>
                      </div>
                      <div>   
                         <label>Password:</label>
                         <input type="password" required="flag" name="password"/>
                      </div>
                      <div>   
                         <label>Retype Password:</label>
                         <input type="password" required="flag" name="password2"/>
                      </div>
                      <div>
                          <input type="button" value="Submit" class="form_butt" />
                      </div>        
                      <p id="reg_error" class="error"></p>  
                </form>

            </section>

        </div> 

    </body> 
</html>

有什么我需要知道的东西不在教程中吗?

1 个答案:

答案 0 :(得分:3)

尝试将代码放入

$(document).ready(function(){    
    // Your code goes here    
});
相关问题