我的脚本可以在jsfiddle中运行,但不能在站点中运行.无法将方法悬停为null吗? [英] My script works in jsfiddle but not site. Cannot call method hover of null?

查看:62
本文介绍了我的脚本可以在jsfiddle中运行,但不能在站点中运行.无法将方法悬停为null吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一个错误,提示未捕获的typeError:无法调用null的方法'hover'. $('#nav li a').hover(function(){在我的JavaScript中.

I'm getting an error that says "Uncaught typeError: cannot call method 'hover' of null" after $('#nav li a').hover(function(){ in my javascript.

站点代码: http://pastebin.com/GjZBEu3s jsfiddle: http://jsfiddle.net/jenga/5rfCC/2/

site code: http://pastebin.com/GjZBEu3s jsfiddle: http://jsfiddle.net/jenga/5rfCC/2/

推荐答案

您的脚本应该位于文档正文中,紧接在</body>标记之前.如果它已加载到<head>中,则它在文档中寻址的元素可能尚未加载.请参见此jsfiddle (请注意选择框架"对话框中的不包装(主体)").

You scripting should be in the body of the document, right before the closing </body> tag. If it's loaded in the <head>, the elements it addresses in the document may not be loaded yet. See this jsfiddle (notice 'no wrap (body)' in the 'Choose framework' dialog).

顺便说一句,仅使用css可以实现类似的效果.在Chrome/Webkit浏览器中使用此 jsfiddle .

By the way, a similar effect could be achieved using css only. Use this jsfiddle in a Chrome/webkit browser.

这篇关于我的脚本可以在jsfiddle中运行,但不能在站点中运行.无法将方法悬停为null吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆