Javascript 未捕获的类型错误:Object#<Object> 没有方法“dispatchEvent”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6331407/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 21:16:32  来源:igfitidea点击:

Uncaught TypeError: Object#<Object> has no method 'dispatchEvent'

javascriptdrupaltypeerrorpicasa

提问by Puyol

I'm trying to combine Drupal with Picasa web integrator.

我正在尝试将 Drupal 与Picasa web integrator结合起来。

I have these 3 lines in the section of my page.tpl.php:

我的 page.tpl.php 部分中有这 3 行:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript" src="/fotos/js/jquery.slimbox2/jquery.slimbox2.js" language="JavaScript"></script>
<script type="text/javascript" src="/fotos/js/jquery.pwi.js" language="JavaScript"></script>

I also added this script to my head section, to test an album (the username and albumname are not important, I tested it offline with my username and album and that worked fine):

我还将这个脚本添加到我的 head 部分,以测试专辑(用户名和专辑名称并不重要,我使用我的用户名和专辑离线测试它并且工作正常):

<script type="text/javascript">

$(document).ready(function() {

    $("#container").pwi({
        username: 'My',
        maxresults: 5,
        mode: 'album',
        album: 'MyAlbum'
    });

});
</script>

Google Chrome gives me this error when I try it on my Drupal-page:

当我在我的 Drupal 页面上尝试时,谷歌浏览器给了我这个错误:

prototype.js:5733Uncaught TypeError: Object#<Object> has no method 'dispatchEvent'

回答by Alex Kahn

It looks like you are also loading prototype.json the page (used by lightbox.js, perhaps?, and that perhaps the $used by both jQuery and Prototype are conflicting. If you really need to use both Prototype and jQuery, look into using jQuery's noConflictmode: http://api.jquery.com/jQuery.noConflict/.

看起来你也在页面上加载prototype.js(被使用lightbox.js,也许?,而且$jQuery和Prototype使用的可能是冲突的。如果你真的需要同时使用Prototype和jQuery,请考虑使用jQuery的noConflict模式:http://api.jquery.com/jQuery.noConflict/

回答by red

Drupal also comes with jQuery, and you cannot simply just add the later version in <script>tags. You can try using Drupal's jquery updateto get a more recent version, or try noConflict(I suspect you will need it anyhow if you want to use Prototype).

Drupal 还带有 jQ​​uery,您不能简单地在<script>标签中添加更高版本。您可以尝试使用Drupal 的 jquery 更新来获得更新的版本,或者尝试noConflict(我怀疑如果您想使用 Prototype,无论如何您都需要它)。