2010-09-18 72 views
0
<script type= "text/javascript" 
     src = "jquery-1.4.2.min.js"></script> 

<script type= "text/javascript"> 


    //<!CDATA[[ 

$(init); 

function init() { 
$("#heading").load("head.html"); 
$("#menu").load("menu.html"); 
$("#content1").load("story.html"); 
$("#content2").load("story2.html"); 
$("#footer").load("footer.html"); 
}; 

    //]]> 

</script> 
+0

难道你不需要使用document.ready函数吗? – 2010-09-18 00:41:13

+0

你在上面的代码片段中包含jquery的地方? – amurra 2010-09-18 00:43:25

+0

我相信可以用$()启动,不需要使用document.ready和jquery – user449914 2010-09-18 00:43:42

回答

7

由于某种原因,jQuery没有加载。

检查你的路径是否真的是src = "jquery-1.4.2.min.js"?或者它可能是:src = "jquery/1.4.2.min.js"

确保你的jQuery被加载。转到源页面并确保您可以阅读它。调试时使用源代码的完整URL而不是相对路径。然后,如果这有效,将其更改为相对路径并查看它是否仍然有效。


您的第一个<script>标签格式不正确:

这是畸形的:

<script type= "text/javascript" 
     src = "jquery-1.4.2.min.js"</script> 


它应该阅读:

<script type= "text/javascript" 
     src = "jquery-1.4.2.min.js"></script> 

(注意>就在</之前)

这种类型的问题存在的一个线索通常是缺少IDE或编辑器中的语法高亮显示。实际上请注意上面两个代码片段之间的Stack Overflow语法高亮区别。


而且CDATA应该

//<![CDATA[ 

,而不是:

//<!CDATA[[ 
+0

固定但仍然说$不是定义 – user449914 2010-09-18 00:34:45

+0

@user 449914 - 检查jquery是否正在加载...尝试将URL作为源代码,然后转到该URL以确保该文件实际存在。 – 2010-09-18 00:42:04

+0

我在本地运行它,所以它应该加载jquery文件.. – user449914 2010-09-18 00:44:26

0

确保您引用您的jquery.js文件正确,测试通过添加警报('打! “);在你的jQuery文件中,如果你不确定。

一旦你有一个排序,请执行下列操作:

<script type= "text/javascript"> 

$(function(){ 
$("#heading").load("head.html"); 
$("#menu").load("menu.html"); 
$("#content1").load("story.html"); 
$("#content2").load("story2.html"); 
$("#footer").load("footer.html");}); 

</script> 

或者如果你想使用你的函数,

function init() { 
$("#heading").load("head.html"); 
$("#menu").load("menu.html"); 
$("#content1").load("story.html"); 
$("#content2").load("story2.html"); 
$("#footer").load("footer.html"); 
}; 

而刚刚结束标记之前调用init()。

0

确保您没有使用jQuery.noConflict(),这将删除$别名以避免与其他JavaScript库的冲突。