为什么 $(document).ready(function()在以下示例中不起作用?
如果我把它拿出来,那么另一个jQuery语句就可以了。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<title>Text Page</title>
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1.3.2");
$(document).ready(function() {
$("p").css("background-color","green");
});
function highlightIt() {
$("p").css("background-color","yellow");
}
</script>
</head>
<body>
<p>this is a test</p>
<form action="">
<div>
<input type="button" value="highlight it" onclick="highlightIt()" />
</div>
</form>
</body>
</html>
答案 0 :(得分:4)
对于Google Load,您必须使用:
google.setOnLoadCallback(function() {
$(document).ready(function() {
// Do something
});
});