对象不支持此属性或方法
正如标题所示,我的网站上出现此错误。我通过IE8开发者调试工具进行了检查,得到了以下导致错误的代码。
<!-- slider js code start -->
<script type="text/javascript">
$().ready(function() {
if(eval(document.getElementById('coda-slider-1')))
{
$('#coda-slider-1').codaSlider();
//jQuery.noConflict(); var $j = jQuery;
}
});
我已经包含了 Chrome 调试工具的屏幕截图。
http://img857.imageshack.us/i/javaerror.jpg
http://img204.imageshack.us/i/javaerror2.jpg
请帮助我弄清楚。
谢谢。
As titled, I'm getting this error on my site. I have checked through the IE8 developer debugging tool, and I have got the following code that caused the error.
<!-- slider js code start -->
<script type="text/javascript">
$().ready(function() {
if(eval(document.getElementById('coda-slider-1')))
{
$('#coda-slider-1').codaSlider();
//jQuery.noConflict(); var $j = jQuery;
}
});
I have included the screenshoot from Chrome debugging tool.
http://img857.imageshack.us/i/javaerror.jpg
http://img204.imageshack.us/i/javaerror2.jpg
Please help me to figure it out.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
请尝试这样做:
您的原始代码显示“使用 jQuery 不选择任何内容,并将此就绪处理程序应用于它”。正确的长手语法是:
另请注意,我已删除
eval
因为它永远不应该被使用,除非它无法避免。更新
查看您的错误屏幕截图,似乎未定义 jQuery(至少没有使用
$
别名。您是否在页面上包含了该脚本?如果是的话,是您在绑定就绪处理程序之前调用jQuery.noConflict()
吗?尝试将此脚本标记放在您发布的代码和 coda 滑块的脚本标记之上:
UPDATE 2
正如 kingjiv 在下面的评论,我错了,
$().ready
可以工作(尽管不推荐),我相信我的第一次更新,注意到 jQuery 似乎没有被定义,是这里的实际问题。 。Try this instead:
Your original code says "select nothing with jQuery, and apply this ready handler to it." The correct long-hand syntax would be:
Also note that I have removed
eval
because it should never, ever be used, unless it can't possibly be avoided.UPDATE
Looking at your error screenshots, it appears that jQuery is not defined (at least not with the
$
alias. Have you included the script on your page? If so, are you callingjQuery.noConflict()
before your ready handler is bound?Try putting this script tag above both the code you posted, and the script tag for the coda slider:
UPDATE 2
As pointed out by kingjiv in the comments below, I was mistaken, and
$().ready
will work (though it is not recommended). I believe my first update, noting that jQuery appears not to be defined, is the actual issue here.我猜您正在尝试检查
coda-slider-1
是否存在?不需要使用eval,如果你使用jquery,不妨用jquery选择元素:
I'm guessing you're trying to check for the existence of
coda-slider-1
?No need to use eval, and if you're using jquery, may as well select the element with jquery:
问题:
$().ready
。使用$(document).ready(function
或简单的
$(function
.为什么使用
document.getElementById
如果 jQuery 已经查找元素
在跨浏览器中使用选择器
方式?只需执行
$("#some").length
即可查看它是否存在。
对于你的情况,我认为也很好
确保
codaSlider()
方法在调用之前加载。
更正代码:
Problems:
$().ready
isn't recommended. Use$(document).ready(function
orsimple
$(function
.Why using
document.getElementById
if jQuery already lookup elements
using selectors in a crossbrowser
way? Just do
$("#some").length
tosee if it exists.
Also in your case I think is good to
ensure that the
codaSlider()
methodis loaded before calling.
Correted code: