Phonegap与jQuery的移动“你好世界”不工作
只是试图让jquery移动电话发射,但我无法让我的你好世界射击。Phonegap与jQuery的移动“你好世界”不工作
所有对Js的引用都是正确的。
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no;" />
<meta charset="utf-8">
<link rel="stylesheet" href="style.css" type="text/css" media="screen" charset="utf-8">
<script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="jquery_mobile.js"></script>
<script type="text/javascript">
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
$(document).ready(function() {
$(document).bind("deviceready", function(){
navigator.notification.alert("hello world");
});
});
}
</script>
</head>
<body>
</body>
</html>
试试这个:
<!DOCTYPE HTML>
<html>
<head>
<meta name="viewport" content="width=320; user-scalable=no" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
<title>Hello With JQuery Mobile</title>
<link rel="stylesheet" href="jquery.mobile/jquery.mobile-1.0rc1.min.css" type="text/css" charset="utf-8" />
<script type="text/javascript" src="jquery.mobile/jquery-1.6.4.min.js"></script>
<script type="text/javascript" charset="utf-8" src="phonegap-1.1.0.js"></script>
<script type="text/javascript" src="jquery.mobile/jquery.mobile-1.0rc1.min.js"></script>
<script type="text/javascript">
var onDeviceReady = function() {
alert("OnDeviceReady fired.");
};
function init() {
document.addEventListener("deviceready", onDeviceReady, true);
}
</script>
</head>
<body onload="init();">
</body>
</html>
您是否在html和js ar位于Xcode中包含引用?
你应该尝试通过在html正文中放置一些东西来开始调试,看看在你编译和运行时是否出现这种情况。
试过,HTML加载正常。 –
尝试取出的addEventListener和功能是这样的:
<script type="text/javascript">
$(document).ready(function(){
$(document).bind('deviceready', function(){
navigator.notification.alert("hello world");
});
});
</script>
没有必要听“deviceready”两次。该文件将首先准备就绪,随后JQM启动设备准备就绪。
我希望它有帮助!
不幸的是,没有快乐 –
@MildFuzz你有没有尝试在调用中放置其他函数来查看它们是否被触发? – dSquared
我有一个类似的问题。注释掉jquery或jquerymobile引用导致应用程序工作,但我无法让它在标题中同时使用。这两个文件都在phonegap的www文件夹中。我什至尝试引用jquery.com的代码,但它没有奏效。
工作魅力,关心为什么要进入一个小细节? –
太棒了!文档尚未准备好添加事件侦听器,直到正文加载。 –
对不起,这是行不通的。我需要一些只会在jQuery,jquery mobile和document body加载后才会触发的东西。我测试了如果我删除了jQuery手机脚本标签会发生什么情况,并且这仍然起作用。我还检查了没有触发的'typeof(jQuery)',表明它不依赖于这些脚本,并且不会等待它们。 –