我正在 VS2015 上开发 cordova appache 应用程序。我想在我的应用程序中使用jquery,就像在网络应用程序中使用它一样。我尝试去做,但没成功。这是我的代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>test</title>
<!-- test references -->
<link href="css/index.css" rel="stylesheet" />
</head>
<body>
<p>Hello, your application is ready!</p>
<!-- Cordova reference, this is added to your app when it's built. -->
<script src="cordova.js"></script>
<script src="scripts/platformOverrides.js"></script>
<script src="scripts/index.js"></script>
</body>
</html>
<script>
$(document).ready(function () {
alert("test!");
});
</script>
请指教。
最佳答案
那里没有链接 jQuery 脚本。当然您需要添加:
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0-alpha1/jquery.min.js"></script>
(或服务器上 jquery 文件的链接)
到你的脚本链接 - 可能在index.js之前。
编辑:您的脚本标记也在 HTML 之外。将其移至 body 标记的底部:
<script>
$(document).ready(function () {
alert("test!");
});
</script>
</body>
</html>
关于javascript - Jquery 不在 cordova 应用程序中运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34614484/