总的来说,我对 jQuery 和 javascript 很陌生,所以也许我错过了一些东西。
我有一个 html 页面,头部有一个指向最新版本 jQuery 的链接...
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
但是,当我加载页面时,我尝试在 head 或单独的 .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>
有什么我需要知道但教程中没有的内容吗?
最佳答案
尝试将代码放入其中
$(document).ready(function(){
// Your code goes here
});
关于jQuery 在 Firebug 控制台上工作,但在页面加载时不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3888261/