![](/img/trans.png)
[英]VS2015 Cordova Sms Plugin Sms.Send doesn't work in Index.JS (ondeviceReady)
[英]Can't get jQuery to work in index.js in Blank Cordova App in Visual Studio 2015
我正在使用 Visual Studio 2015 创建一个空白的 Apache Cordova 应用程序,如下链接所示: http : //i.imgur.com/1PL3el0.png
使用 NuGet 包管理器,我已将 jQuery 添加到我的项目中: http : //i.imgur.com/smhVnYZ.png
根据我的基本理解,通过 NuGet 管理器添加 jQuery 不会向我的 index.html(或 index.js)添加脚本标记,而是将 get 打包在 Cordova.js 文件中。
我在 index.html <a href="#" id="mylink">Link</a>
添加了以下基本链接标记
但是,如果我尝试在 index.js 文件中使用 jQuery 引用该锚标记,则会收到以下错误: Uncaught ReferenceError: $ is not defined
但是,在调试窗口中,在 javascript 控制台中,我可以很好地使用 jQuery 访问元素。 我在这里缺少一些基本的东西。 有人可以解释为什么我的 jQuery 失败了吗?
这是我的 index.html 和 index.js 文件:
索引.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<!--
Customize the content security policy in the meta tag below as needed. Add 'unsafe-inline' to default-src to enable inline JavaScript.
For details, see http://go.microsoft.com/fwlink/?LinkID=617521
-->
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *">
<title>Office365Test3</title>
<!-- Office365Test3 references -->
<link href="css/index.css" rel="stylesheet" />
</head>
<body>
<p>Test 3</p>
<br />
<a href="#" id="mylink">Link</a>
<!-- 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>
索引.js
/// <reference path="../../Scripts/jquery-2.1.4.min.js" />
/// <reference path="../../Scripts/jquery-2.1.4.min.js" />
// For an introduction to the Blank template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkID=397704
// To debug code on page load in Ripple or on Android devices/emulators: launch your app, set breakpoints,
// and then run "window.location.reload()" in the JavaScript Console.
(function () {
"use strict";
document.addEventListener( 'deviceready', onDeviceReady.bind( this ), false );
function onDeviceReady() {
// Handle the Cordova pause and resume events
document.addEventListener( 'pause', onPause.bind( this ), false );
document.addEventListener( 'resume', onResume.bind( this ), false );
// TODO: Cordova has been loaded. Perform any initialization that requires Cordova here.
$('#mylink').css('display', 'none');
};
function onPause() {
// TODO: This application has been suspended. Save application state here.
};
function onResume() {
// TODO: This application has been reactivated. Restore application state here.
};
} )();
尝试将您的 jQuery 文件移动到www/scripts
目录,并从您的index.html
文件中引用它们。 默认情况下,NuGet 将它们放在项目根目录的Scripts
文件夹中,该文件夹似乎不可访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.