简体   繁体   English

jQuery .click()在Android上不起作用

[英]Jquery .click() not working on android

I have a mobile web app where the user clicks on an empty canvas element to upload a photo. 我有一个移动网络应用程序,用户在其中单击一个空的画布元素以上传照片。 The way I am doing this is with an input type="file" element and when the user clicks the empty canvas (if no image is already loaded) JavaScript simulates a 'click' on the hidden input type file element which pops up the file select dialogue. 我这样做的方法是使用input type =“ file”元素,并且当用户单击空白画布(如果尚未加载任何图像)时,JavaScript在隐藏的输入类型file元素上模拟“单击”,从而弹出文件选择对话。

It is working everywhere but android, any ideas? 除了android,它在任何地方都可以使用,有什么想法吗?

$("#canvas").click(function() {
    if (!imageLoaded) {
        $('#imageLoader').click();  // <-- this is the issue here
    }
});

Thanks! 谢谢!

try this code. 试试这个代码。

$(document).on("mousedown touchstart","#canvas" ,function() {
        if (!imageLoaded) {
            $('#imageLoader').trigger('click');  // <-- this is the issue here
        }
});

Thanks 谢谢

You will want to trigger the click - http://jsfiddle.net/6AmLZ/1/ 您将要触发点击-http://jsfiddle.net/6AmLZ/1/

$('#imageLoader').click(function() {
    console.log('image loader has been clicked');
});
$("#canvas").click(function() {
    $('#imageLoader').trigger('click');
});

http://api.jquery.com/trigger/ http://api.jquery.com/trigger/

While what you're doing will trigger the second click I have found the Android platform wanting more sometimes. 虽然您所做的会触发第二次点击,但我发现Android平台有时需要更多。 I would also try, as others have suggested, that nothing is overlaying the canvas on the Android platform and it is using your CSS as you would expect it to. 正如其他人所建议的那样,我还将尝试在Android平台上没有覆盖画布的任何内容,并且按预期使用CSS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM