[英]onclick event doesn't work on iphone
I have form which should upload image.我有应该上传图片的表格。 each form placed in iframe
放置在 iframe 中的每个表单
<body style="margin: 0; padding: 0; height: 100%; cursor: pointer;" onclick="document.querySelector('.register-upload-input').click()">
<form method="POST" action="http://127.0.0.1:8000/de/client/registerupload" accept-charset="UTF-8" enctype="multipart/form-data">
<input class="register-upload-input" style="display: none;" onchange="document.querySelector(".preloader").style.display="block";document.querySelector("form").submit();" accept=".jpg,.jpeg,.png" name="image" type="file">
</form>
</body
so I click on iframe, file upload dialog appears and I can choose image.所以我点击 iframe,出现文件上传对话框,我可以选择图像。
body
element has onclick
event. body
元素有onclick
事件。 everything works fine, but when I try to upload images with iphone nothing happens, dialog prompt dosn't show up.一切正常,但是当我尝试使用 iphone 上传图像时,没有任何反应,对话框提示不显示。 it works on android, but doesn't work on iphone.
它适用于android,但不适用于iphone。 I did research, usually such problem happens cause the element should has
cursor: pointer
in styles.我做了研究,通常发生这样的问题是因为元素应该在样式中具有
cursor: pointer
。 I added it, but nothings changed我添加了它,但没有任何改变
Do not set display:none
on <input>
,you can set height:0px
instead.不要在
<input>
上设置display:none
,你可以设置height:0px
。
EDIT:编辑:
I checked my note, find that there has been a same question on stackoverflow.查了一下笔记,发现stackoverflow上也有同样的问题。
the same question is here .同样的问题在这里。
Three things are causing this problem:
导致此问题的三个原因:
At javascript, removing return false;
在 javascript 中,删除 return false; of event listener.
事件监听器。
At the stylesheet, the element which calls the action must have the property cursor: pointer;.
在样式表中,调用动作的元素必须具有属性 cursor:pointer;。 Probably Apple put this requirement in these calls for best feedback on user interface.
可能苹果在这些呼吁中提出了这一要求,以获得对用户界面的最佳反馈。
Again at the stylesheet, we can't setting display: none;
再次在样式表中,我们不能设置 display: none; for hidden input because some browsers don't accept clicks on elements that aren't displayed.
对于隐藏输入,因为某些浏览器不接受对未显示元素的点击。
Adding the following CSS to the IFrame content.将以下 CSS 添加到IFrame内容。
html, body {
touch-action: auto;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.