Hug*_*lio 10 javascript safari mobile-safari ios ios9
我有一个上传字段的网站,但input
隐藏了display: none;
,我有一个div
用于调用此操作.
它适用于iOS 8,但现在在iOS 9更新后,当我触摸div时没有任何反应.
我尝试使用[0].click()
或纯粹的VanillaJS document.getElementById('file_input').click()
,没有任何作用.
所有这些方法都适用于iOS 5和iOS 8.
如果你愿意,可以在JSFiddle上链接到这个例子: https ://jsfiddle.net/o1r265tz/6/embedded/result/
$(document).ready(function(){
$(document).on('click touchstart', '.upload-box', function(e){
e.stopPropagation();
$('.form-upload input.file-input').trigger('click');
$('.debug').append('<p>Clicked!</p>');
console.log('Clicked!');
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
.upload-box {
border: 3px solid #999;
padding: 10px;
text-align: center;
border-radius: 5px;
font-size: 35pt;
font-family: Arial;
color: #555;
}
.form-upload {
display: none;
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="upload-box">Click here to upload =D</div>
<form class="form-upload" enctype="multipart/form-data">
<input class="file-input" id="file_input" type="file">
</form>
<div class="debug"></div>
Run Code Online (Sandbox Code Playgroud)
有三件事导致了这个问题:
在javascript,删除return false;
事件监听器.
在样式表中,调用操作的元素必须具有该属性cursor: pointer;
.苹果可能会在这些要求中提出这一要求,以获得有关用户界面的最佳反馈.
再次在样式表中,我们无法设置display: none;
隐藏输入,因为某些浏览器不接受未显示的元素的点击.
归档时间: |
|
查看次数: |
14086 次 |
最近记录: |