我使用 Camera Cordova 的代码有什么问题?

What is wrong with my code to use Camera Cordova?

我已经尝试了几个小时。我确定这是一个支架或我想念的愚蠢的东西。我已经问过与此相关的问题,但没有解决我的问题。

我只是想拍张照片并将其存储在变量中以备后用。

我最大限度地简化了我的代码。有一页,如下:

    <!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

它在我的 mIphone 上正常启动,但单击按钮时没有任何反应。 有什么帮助吗?

附带问题,当应用在 Iphone 上 运行 时,"developper javascript console" 是什么?

在设备就绪之前,您不能使用 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,
            });

}

似乎一切都很好,除了第 no:37

行的一个语法错误

点击后在第37行添加“,”...

$("#prendrephoto2").bind("click", function(){
       alert('je suis le bouton 2');
});

改变这个。

$("#prendrephoto2").bind("click"function(){
 alert('je suis le bouton 2');
});

至此。

$("#prendrephoto2").bind("click",function(){
 alert('je suis le bouton 2');
 alert('Click Working');
});

你好像漏掉了逗号所以是语法错误。

希望这能解决您的问题。