简体   繁体   English

按钮不在移动设备上工作,但适用于PC引导程序

[英]Button not working on Mobile Devices but works on PC bootstrap

I created a bootstrap button that has a link inside. 我创建了一个内部有链接的引导按钮。 Which looks like this: 看起来像这样:

在此输入图像描述

When you hover on it: 当你将鼠标悬停在它上面时:

在此输入图像描述

This is the code inside the button: 这是按钮内的代码:

 <div class="s-8"><button type="button" onClick="javascript:location.href = 'administration.php';">Administration</button></div>

The logout button: 注销按钮:

<div class="s-4"><button type="button" onClick="javascript:location.href = 'logout.php';">Logout</button></div>

This button works fine on the PC(IE, SAFARI, FireFox, Chrome, Opera) browser(takes me to the administration page, but it doesn't work on the Mobile devices. 此按钮在PC(IE,SAFARI,FireFox,Chrome,Opera)浏览器上正常工作(将我带到管理页面,但它不适用于移动设备。

I did the same thing for the logout button, and it works fine on PC and Mobile Devices. 我为注销按钮做了同样的事情,它在PC和移动设备上运行良好。 I am now puzzled. 我现在感到困惑。

The issue may be that you're using the onClick event which won't register on a mobile device (as you don't click - you tap). 问题可能是您正在使用不会在移动设备上注册的onClick事件(因为您没有点击 - 您点按)。

This answer explains how to use the "touchstart" event which will work on a mobile. 这个答案解释了如何使用可在移动设备上运行的“touchstart”事件。

https://stackoverflow.com/a/22015946/2619909 https://stackoverflow.com/a/22015946/2619909

I know this might be a weird answer. 我知道这可能是一个奇怪的答案。 But in some cases mobile clickevents dont work unless you put the style: cursor:pointer; 但在某些情况下,移动的clickevents不会工作,除非你把样式:cursor:pointer; to your button. 到你的按钮。

Mobile clickEvents are handled very differently, the first "click" or "tap" might be interpreted as a HOVER instead of the click which you are looking for. 移动点击事件的处理方式非常不同,第一个“点击”或“点按”可能会被解释为HOVER而不是您要查找的点击。

So try setting the CSS style of the button to : cursor:pointer; 因此,尝试将按钮的CSS样式设置为:cursor:pointer;

unfortunately neither setting cursor:pointer; 遗憾的是既没有设置cursor:pointer; nor adding a touchstart event listener 也不添加touchstart事件监听器

$(document).ready(function() {
  $('#button_id').on('click touchstart', function() {
    window.location.href = "/url";
  });
});

as @noa-dev and @GitPauls suggested worked for me. @ noa-dev和@GitPauls建议为我工作。 for reference I tested on my phone7 (ios11.4 and safari) 作为参考我在我的手机7上测试过(ios11.4和safari)

working solution: I set the z-index of the button to a large positive number and the button now works. 工作解决方案:我将按钮的z-index设置为一个大的正数,按钮现在可以正常工作。

#button_id{
  z-index: 99;
}

solution found thanks to Daniel Acree https://foundation.zurb.com/forum/posts/3258-buttons-not-clickable-on-iphone . 感谢Daniel Acree https://foundation.zurb.com/forum/posts/3258-buttons-not-clickable-on-iphone I don't know if this generalizes to all iphone/mobile devices. 我不知道这是否适用于所有iphone /移动设备。

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

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