所以我有这个按钮:

<div class="btndiv" style="margin-top:4vh;">
<button class="btngaleria" onclick="capturePhoto()" style="margin-top:3vh; background-color: #5f919d;"> Camâra </button>
<button class="btngaleria" onclick="getPhoto()" style="margin-top:3vh; background-color: #5f919d;"> Galeria </button>
<div style="text-align:center;margin:20px;">
<img id="cameraPic" src="" style="width:auto;height:120px;"></img>
</div>
<button class="btngaleria" onclick="photoUpload()" style="margin-top:3vh; background-color: #5f919d;"> Enviar </button>

</div>


当我单击每个按钮时,我就会执行以下功能:

function capturePhoto(){
                    navigator.camera.getPicture(picOnSuccess, picOnFailure, {
                        destinationType: Camera.DestinationType.FILE_URI,
                        sourceType: navigator.camera.PictureSourceType.CAMERA,
                        correctOrientation: true
                    });
                }

                function getPhoto(){
                    navigator.camera.getPicture(picOnSuccess, picOnFailure, {
                        destinationType: Camera.DestinationType.FILE_URI,
                        sourceType: navigator.camera.PictureSourceType.PHOTOLIBRARY,
                        correctOrientation: true
                    });
                }

function photoUpload() {
                    var options = new FileUploadOptions();
                    options.fileKey = "file";
                    options.fileName = sPicData.substr(sPicData.lastIndexOf('/') + 1);
                    options.mimeType = "image/jpeg";
                    options.chunkedMode = false;

                    var params = new Object();
                    params.sitio = id;
                    options.params = params;

                    ft = new FileTransfer();
                    ft.upload(sPicData, "http://pedrofidalgo.pt/bilapoint/upload.php", win, fail, options);
                }

                function win(){
                    alert("Foto enviada com sucesso, obrigado!");
                }

                function fail(){
                    alert("O envio da foto falhou, tente de novo.");
                }


我正在使用framework7,所以我不能在按钮上使用事件绑定,我必须将它们放在js端,如下所示:

$$('#buttonClass').on('click', function (e) {
    myApp.alert('Clicked registerButton!');
});


我已经从framework7文档中阅读了有关事件处理程序和操作表的信息,但是我仍然无法使其正常工作...

https://framework7.io/docs/action-sheet.html

我是javascript的初学者,有人可以给我帮助吗?

提前致谢 :)

最佳答案

您使用的是错误的,应该将其绑定到可以监听点击的东西,然后检查它是否在您想要的东西上。例如:

$('body').on('click', '#buttonClass', function(){
    // do something
});


我不知道framework7,但是如果它是单页应用程序,请不要将内容绑定到主体,因为它将保留在那里,除非您计划将它们取消绑定或在某个时候清理它。

09-11 06:46