2011-07-28 111 views
0

我有和jQuery加载和外部JavaScript(functions.js)文件加载index.html。但是外部js文件中的函数不起作用。我可以在Chrome开发工具的资源标签中看到jQuery和functions.js文件的加载。此外,如果我剪切和粘贴我的功能到控制台它的作品。请帮忙。外部JavaScript注册

$(document).ready(function() { 
topMenuShare(); 
}); 

function topMenuShare(){ 
$('#topNavShare').click(function(){ 
    $('#shareMenu').show(); 
}); 
} 

HTML下面

<script type="text/javascript" src='js/jquery1.6.2.min.js'></script> 
<script type='type/javascript' src='js/functions.js'></script> 

UPDATE: 有没有错误消息显示,Chrome浏览器开发工具,萤火虫和的jsfiddle说一切都很好。当我说它不起作用,我的意思是脚本加载,没有错误信息,但是当我点击'#topNavShare'show()事件不会触发。

clickable元素是一个空白的div,其高度,宽度和background-image在CSS中定义。

 <div id="topNav"> 
      <div id="topNavLogin" class="topNavButtons"> 
      </div> 
      <div id="topNavShare" class="topNavButtons"> 
       <div id='shareMenu'> 
        <div id='shareMenuEmail' class='shareMenuitem'> 
        </div> 
        <div id='shareMenuFacebook' class='shareMenuitem'> 
        </div> 
        <div id='shareMenuTwitter' class='shareMenuitem'> 
        </div> 
        <div id='shareMenuGooglePlus' class='shareMenuitem'> 
        </div> 
       </div> 
      </div> 
      <div id="topNavLiveChat" class="topNavButtons"> 
      </div> 
      <div id="topnavSearch" class="topNavButtons"> 
      </div> 
     </div> 

CSS ...

#topNav{ 
position: absolute; 
width: 400px; 
height: 25px; 
top: 0px; 
right: 15px; 
} 
.topNavButtons{ 
height: 25px; 
float: left; 
margin-right: 5px; 
} 
#topNavShare{ 
width: 60px; 
height: 25px; 
background-image: url('http://localhost:8888/assets/hpSprites.png'); 
background-position: -63px -41px; 
} 
#topNavShare:hover{ 
background-position: -63px -11px; 
} 

希望这是有帮助的。对不起,如果这似乎很疯狂,我一直在看这个看似简单的问题一段时间,我有一个快速接近的截止日期。

+3

东西在JS错误控制台页面加载时? –

+2

你是什么意思'不起作用'?怎么了?你得到什么错误信息? –

+2

从你提供的信息来看,没有什么是错的, 这里有一个使用你的代码的jsFiddle http://jsfiddle.net/nwe44/aM8Ag/你可以给你的网站的链接? –

回答

1
<script type='type/javascript' src='test.js'></script> 

应该

<script type="text/javascript" src="test.js"></script> 
+0

固定!非常感谢。这些愚蠢的小眼睛疲劳的东西总是让我感到厌倦。 – Andalinmicphew