【问题标题】:Reference Error while working with javascript in phonegap在 phonegap 中使用 javascript 时出现参考错误
【发布时间】:2011-04-06 07:06:36
【问题描述】:

我正在尝试使用 twitter api 的 phonegap 和 jquery 插件向我的 android 模拟器显示推文。

当我在浏览器中运行代码时,它工作正常,但是当我尝试在模拟器上运行它时,它在 ddms 控制台中显示一些参考错误......

这里是错误...

04-06 12:18:40.813: ERROR/Web Console(486): ReferenceError: Can't find variable: $ at file:///android_asset/www/index.html:32

这是我写的代码...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <meta charset="UTF-8" />
  <title>Tweet! Put Twitter on your site with this simple, unobtrusive jQuery widget</title>
  <link href="index.css" rel="stylesheet"/>
  <link href="jquery.tweet.css" rel="stylesheet"/>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
  <script src="jquery.tweet.js" charset="utf-8"></script>
  <script>
    $(function(){
    alert("Hello . . .sms. .. . ");
      $(".tweet").tweet({
        join_text: "auto",
        username: "VJAnusha",
        avatar_size: 48,
        count: 10,
        auto_join_text_default: "we said,",
        auto_join_text_ed: "we",
        auto_join_text_ing: "we were",
        auto_join_text_reply: "we replied",
        auto_join_text_url: "we were checking out",
        loading_text: "loading tweets..."
      });
    });
  </script>
</head>
<body>  

  <div class='tweet query'></div>
  <script type="text/javascript">
    **$(function(){ $(".example").each(function(i, e){ eval($(e).text()); }); });**
  </script>

</body>
</html>

我已经突出显示它向我显示错误的行...。 谢谢

【问题讨论】:

  • 可能是因为您试图访问 DOM 中不存在的 example 类而出现此错误。尝试放置一个现有的类。

标签: javascript android cordova


【解决方案1】:

错误是说它找不到 JQuery 库。尝试验证您的模拟器是否连接到互联网。

无论如何,当部署应用程序而不是使用来自 Google 的 CDN 的 JQuery 时,您应该只需下载 JQuery 并使用本地版本

<script src="jquery.min.js"></script>

否则,您的应用将无法在没有互联网连接的情况下运行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-30
    • 2019-09-10
    • 2023-03-21
    • 2022-07-07
    • 2020-06-04
    • 1970-01-01
    • 2014-05-05
    • 1970-01-01
    相关资源
    最近更新 更多