我已经尝试了好几个小时的所有方法。我确信这是一个括号或我错过的一个愚蠢的东西。我已经问过与此相关的问题,但这并没有解决我的问题。
我只是想拍摄一张照片并将其存储在变量中以便稍后使用。
我最大限度地简化了我的代码。有一页,内容如下:
<!doctype html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>Titre de la page</title>
<meta name="viewport" content="width=device-width,height=device-height,initial-scale=1"/>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" />
<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<div class="ui-btn" id="prendrephoto1"> Prendre photo equipe1</div>
<button id="prendrephoto2"> Prendre photo equipe2</button>
<div id="myImage"></div>
<a class="ui-btn" href="#page2">Jouer</a>
</body>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script>
$(document).ready(function(){
var photo1;
var photo2;
$("#prendrephoto2").bind("click"function(){
alert('je suis le bouton 2');
});
$("#prendrephoto1").bind("click",function(){
alert("it is starting");
navigator.camera.getPicture(onSuccess, onFail,
{ quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType:Camera.PictureSourceType.Camera, });
});
function onSuccess(imageURI) {
alert("It is working");
//var image = document.getElementById('myImage');
//image.src = imageURI;
}
function onFail(message) {
alert('Failed because: ' + message);
}
//derniere balise jquery
});
</script>
</html>
为了确保我做的每件事都是正确的,下面是 xml 和插件的 2 个屏幕截图。
然后,在终端中:
cordova run --device
它在我的手机上正常启动,但单击按钮时没有任何反应。 请问有什么帮助吗?
一个附带问题,当应用程序在 Iphone 上运行时,“开发者 JavaScript 控制台”是什么?
最佳答案
在deviceready之前,不能使用navigator.camera功能。
你应该这样写:
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
navigator.camera.getPicture(onSuccess, onFail,
{
quality: 50,
destinationType: Camera.DestinationType.FILE_URI,
sourceType: Camera.PictureSourceType.Camera,
});
}
关于javascript - 我使用 Camera Cordova 的代码有什么问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35719382/