2010-10-08 64 views
4

我对jQuery和JavaScript一般都很陌生,所以也许我错过了一些东西。jQuery适用于Firebug控制台,但不适用于页面加载

我有一个链接到头部的最新版本的jQuery的html页面...

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

但任何jQuery的代码,我尝试任何地方执行......在头部或独立.js文件,当我加载页面时不会运行。然而,正常的JavaScript呢。

Firebug确认jQuery库已经加载,当我点击脚本或Dom ...控制台甚至会接受并运行我的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

你能所链接的页面或张贴一些HTML?此外,您可能更适合使用Google API版本的jQuery:http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js – mway 2010-10-08 06:43:51

+0

感谢mway ...只是更改了jQuery链接并张贴了html。 – cybermotron 2010-10-08 06:53:48

+0

和'index4.js'里面有什么? – Reigel 2010-10-08 06:54:59

回答

3

尝试把你的代码中

$(document).ready(function(){  
    // Your code goes here  
}); 
+0

+1经典.... – Reigel 2010-10-08 06:50:33

+0

非常感谢你!它现在是一种享受! – cybermotron 2010-10-08 07:02:16

+1

@cybermotron,如果它是正确的,请接受Jakub的回答。 – 2010-10-08 07:10:54

相关问题