这是angular。我有一个按钮,它在较大的屏幕上工作得很好(例如,只需简单点击一下即可,但如果是在iphone上,则只需双击即可使用(它在android上运行得很好)。它应该也能在oneclick上工作。警报是在单个剪辑上触发的,但不是照片上传。有人能有一个想法吗?为什么会这样?谢谢。
$scope.triggerUploadPhoto = function () {
var width = $(window).width();
alert(123);
if(width< 768){
$('#sidebar').css('display','');
$('#sidebar').addClass('modal-hidden');
$('#side-modal-upload-photo').removeClass('active-modal');
$('#side-modal-upload-photo').addClass('modal-hidden');
$('.five-item-on-hover').css('background-color','transparent');
}
$('#photo-upload').trigger('click');
$('.stored-images').trigger('click');
$scope.toggleUploadPhoto();
}发布于 2021-01-28 23:33:32
它在chromium浏览器上工作得很好,但有时可能不能在safari上工作。最好的方法是使用jQuery并使用touchstart事件,而不是按钮上的onclick事件。或者,为了涵盖所有原因,您还可以在元素上使用ontouchstart事件。
所以,如果HTML代码看起来像这样,
<html>
<body>
<button id="redirectButton">Redirect Me!</button>
</body>
</html>然后我们可以在<button>元素中添加下面这一行
ontouchstart="myFunction()"并在JS中定义您的myFunction()。但一种更安全的方法(更安全:总而言之有效)是使用jQuery
只需在jQuery的head部分插入任何html,并在JS中添加以下行,然后定义元素
$(document).ready(function(){
$('#buttonID').on('click touchstart', function() {
//Your code here
});
});下面是示例:
/*jQuery - include in JS*/
$(document).ready(function(){
$('#redirectButton').on('click touchstart', function() {
window.location.href="http://example.com";
});
});<!--HTML-->
<html>
<head>
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
</head>
<body>
<button id="redirectButton">Take Me To Example.com</button>
</body>
</html>
如果您使用bootstrap,但仍然不起作用,那么您可能需要引用此线程:Button not working on Mobile Devices but works on PC bootstrap
https://stackoverflow.com/questions/65939763
复制相似问题