【问题标题】:$(...).function is not a function jQuery$(...).function 不是一个函数 jQuery
【发布时间】:2015-10-09 19:06:29
【问题描述】:

我知道这个问题已经在以前的帖子中发布过,但没有任何帮助,这让我发疯了,我更确定答案很简单,但我对 javascript 真的很陌生

我正在尝试从那里整合这个 raptor-konami 代码:http://zurb.com/playground/jquery-raptorize

所以我 c/p 我的 html 文件文件夹中的所有内容,我在我的 head 中获得了 src 文件夹,但我在控制台中不断收到此错误:

Uncaught TypeError: $(...).raptorize is not a function

我真的不知道为什么。这是我的头部内容,与插件文件夹中提供的示例 html 文件中的内容完全相同(标题页除外),并且有效!!!

<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />    
    <title>Personnal Website</title>
    <!-- jQuery: Grab Google CDN jQuery. fall back to local if necessary -->
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script>!window.jQuery && document.write('<script src="jquery-1.4.1.min.js"><\/script>')</script>

    <!-- The raptorize file  -->
    <script src="jquery.raptorize.1.0.js"></script>

    <!-- For the button version -->


    <!-- For the Konami Code version -->
    <script type="text/javascript">
      $(window).load(function() {
        $('.button').raptorize({
          'enterOn' : 'konami-code'
        });
      });
    </script>

    <!-- For the Timer version -->
    <!-- <script type="text/javascript">
$(window).load(function() {
$('.button').raptorize({
'enterOn' : 'timer',
'delayTime' : 2000
});
});
</script>   
-->

    <link rel="stylesheet" href="css/demo-styles.css" />

  </head>

jquery.raptorize.1.0.js的源码可以看这里:

http://zurb.com/playground/uploads/upload/upload/254/jquery.raptorize.js

我已经尝试了很多东西,比如将 de $ 更改为 jQuery,将 (document).load 更改为 (document).ready,但没有任何效果我仍然在控制台中收到此错误,我不知道为什么。 . 有人可以帮帮我吗?

非常感谢。

【问题讨论】:

  • @244an — 为什么?万一将方法绑定到 jQuery 对象的时间出现问题,尝试尽快访问它不会有帮助。
  • @244an — 我的观点是正确的。
  • @damouf 检查浏览器的网络选项卡并确保正确加载了 raptorize 脚本。
  • @damouf - 您网站上的 jquery.raptorize.1.0.js(如果存在)可能与您尝试使用它的页面不在同一个文件夹中。
  • @244an 应尽可能避免尝试和错误编程。努力了解为什么您编写自己编写的代码。

标签: javascript jquery html function


【解决方案1】:

在你的代码中,行号:135,请去掉jQuery 1.8.2不必要的重新初始化:

<!--====================================end demo wrapper================================================-->
<script src="js/jquery-1.8.2.min.js"></script>

这将删除旧的 jQuery 并用新的重写它。如果需要,您可以执行以下操作:

$jq = jQuery.noConflict();

这会保留其他所有内容,让$ 为您工作。是的,正如我在之前的评论中所说,请改用$(document).ready() 事件:

$(document).ready(function () {
    $('.button').raptorize({
        'enterOn' : 'konami-code'
    });
});

【讨论】:

  • 天哪,我很确定这是非常明显的事情……我完全忘记了之前的那条线……现在可以了!非常感谢......非常新的问题:)
  • @damouf 很高兴它帮助了你。
  • @damouf,嗯?这与我在回答中所写的解决方案相同。我的投了反对票。我不明白。
  • 反对票并不重要,他们可以在那里,但有时最好知道你为什么得到他们。尤其是在这种情况下。
  • @244an 和 Praveen,对不起,我赞成你的两个答案...有些人似乎并不喜欢他们,尽管他们实际上解决了我的问题...:/
猜你喜欢
  • 2019-11-06
  • 2017-11-28
  • 2018-06-01
  • 2020-05-11
  • 2012-01-30
  • 2013-08-04
  • 2022-01-11
  • 2011-12-18
  • 1970-01-01
相关资源
最近更新 更多