jQuery Slider Uncaught TypeError: Object #<Object> has no method 'data'

最后都变了- 提交于 2019-12-10 20:20:57

问题


I am getting the following error HERE

The error reads: Uncaught TypeError: Object # has no method 'data'

I cannot figure out for the life of me where this error is originating from!

If anyone has even the slightest clue, please let me know!

Thank you,

Evan


回答1:


It's originating from "jquery.nivo.slider.pack.js" and more precisely is complaining about element.data is not a function at line 67 (Firebug is a great tool for such debugging :-) ). I am not entirely sure, but it could be because of the following code in your html:

<script type="text/javascript">
$(window).load(function() {
    $('#slider').nivoSlider();
});
</script>

$(window).load will fire as soon as the window is loaded at which point it could be that the slider div is not present in the DOM. So, try changing this to:

<script type="text/javascript">
$(document).ready(function() {
    $('#slider').nivoSlider();
});
</script>

This will ensure that the DOM has been painted and available for the plugin to work on. Also, it looks like the plugin expects an 'element' argument, whereas you are passing none, which could be the reason for element.data to be undefined. For this you can try:

$('#slider').nivoSlider($(this));

Hope one of them works for you.




回答2:


Incase anyone is stuck with the same thing, live() is deprecated replaced with on(), you need to use a newer version of nivo or an older version of jquery, jquery-1.8.0 works.



来源:https://stackoverflow.com/questions/7744973/jquery-slider-uncaught-typeerror-object-object-has-no-method-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!