问题
I have really strange problem with fancybox(2.x). I was using this script for ages but i hadn't experienced such problem before.
So, i have website: http://tinyurl.com/6mx7an8 and i've included every jquery/fancybox files as manual says but the JS console gives me the error
Uncaught TypeError: Object [object Object] has no method 'fancybox'
Have you any idea what am i doing wrong? Any help would be appreciated :)
回答1:
There are couple of issues in your website.
- You are including jQuery library 2 times one before and after including fancybox plugin js because of which the plugin which is added is cleared by second jQuery library inclusion.
- There is some other library which is overridding
$
, so your code is not working because$
is not an alias forjQuery
anymore. You can usejQuery.noConflict()
to avoid conflicts with other libraries on the page which use the same variable$
.
回答2:
Looks like jQuery is included twice, once near the top of the head and once near the bottom.
回答3:
I had a similar problem. Somehow, jQuery was being loaded twice. Turns out while testing something, I added a drupal_add_js line to load jquery in a block, which was disabled, but Drupal still evaluated the PHP in the disabled block.
When I removed the drupal_add_js line from the block, jQuery loaded fine, once per page.
回答4:
I have a css unify php script on my website that added both jquery and jquery postmessage plugin into the same javascript file.
So it was giving me the error above.
I have loaded the jquery postmessage separately without unifying it and it stopped giving me the error.
回答5:
I got it working with this code
<script type="text/javascript">
(function( $ ) {
$(document).ready( function( ) {
$("a#fancyBoxLink").fancybox({
'href' : '#popupvid',
'titleShow' : false,
'transitionIn' : 'elastic',
'transitionOut' : 'elastic'
});
});
})(jQuery);
</script>
回答6:
Jquery sub library may included in main library ,For example jquery.ui.sortable.js i have included in jquery-ui.js while downloading and i added again it was giving a error for me.
script type="text/javascript" src="vendor/js/jquery-ui.js">
script type="text/javascript" src="vendor/js/jquery.ui.sortable.js">
so verify sub library included or not
来源:https://stackoverflow.com/questions/9070979/uncaught-typeerror-object-object-object-has-no-method-fancybox