![](/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.