jQuery的不工作的PhoneGap [英] Jquery not working with phoneGap

查看:121
本文介绍了jQuery的不工作的PhoneGap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的PhoneGap,这code加载完美的我的Andr​​oid mobile.But当我点击它不显示文本的按钮。

 <!DOCTYPE HTML>
< HTML和GT;
< HEAD>
  <脚本类型=文/ JavaScript的字符集=utf-8SRC =科尔多瓦-2.4.0.js>< / SCRIPT>
<脚本的src =// ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js\">
< / SCRIPT>
<脚本>
$(文件)。就绪(函数(){
  $(#BTN1)。点击(函数(){
    $(#测试1)文本(世界,你好!)。
  });
});
< / SCRIPT>
< /头><身体GT;
< p n =测试1>< / P>
<按钮ID =BTN1>设置文字< /按钮>< /身体GT;
< / HTML>


解决方案

我不认为jQuery是被加载到页面中。

您已经引用为

 <脚本的src =// ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js\">

这表示使用任何协议,当前页面被从服务器。在你被从文件服务的移动设备://所以实际请求的浏览器,使获取的脚本是:

 文件://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js

您需要指定要使用或计划否则它包含在PG项目本身。

I am using phonegap, and this code loads perfectly in my android mobile.But When i click the button it does not shows the text.

    <!DOCTYPE html>
<html>
<head>
  <script type="text/javascript" charset="utf-8" src="cordova-2.4.0.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(document).ready(function(){
  $("#btn1").click(function(){
    $("#test1").text("Hello world!");
  });
});
</script>
</head>

<body>
<p id="test1"></p>
<button id="btn1">Set Text</button>

</body>
</html>

解决方案

I don't think that JQuery is being loaded into the page.

You have referenced it as

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">

which says use whatever protocol the current page is being server from. On a mobile device you are being served from file:// so the actual request the browser makes to fetch the script is:

file://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js

You need to specify the scheme you want to use or else include it in the PG project itself.

这篇关于jQuery的不工作的PhoneGap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆