我正在尝试使用phonegap 3.0加载jquery并且没有任何事情发生。
例如,这有效:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Hello World</title>
</head>
<body>
<div class="app">
<input type="button" value="click me" id="myButton" onclick="alert('hello')" />
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
</script>
</body>
</html>
但这不是:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="format-detection" content="telephone=no" />
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
<link rel="stylesheet" type="text/css" href="css/index.css" />
<title>Hello World</title>
</head>
<body>
<div class="app">
<input type="button" value="click me" id="myButton" />
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript">
app.initialize();
$(document).ready(function(){
$('#myButton').click(function(){
alert('hello');
});
});
</script>
</body>
</html>
我不能为我的生活弄清楚这一点。我在正确的目录中有jquery
答案 0 :(得分:2)
您的jQuery代码需要在onDeviceReady
(在index.js中找到)而不是document.ready中运行。
答案 1 :(得分:0)
我不确定具体是什么问题,但我更新了Xcode,现在一切正常。另外,在我更新Xcode之前,简单地将它放在onDeviceReady中仍然无效。