首页 > 解决方案 > 为什么我的移动设备上的 Bootstrap 按钮不起作用?

问题描述

我的网站上有按钮,可以在桌面上工作,但不能在移动设备上工作。

<button type="button" class="btn btn-primary rounded-0"><a href=" 
https://google.com">Google</a></button>

我知道在移动设备上我点击而不点击。但是如果可能的话,我怎样才能在没有js的情况下触发水龙头呢?

标签: twitter-bootstrapbuttonbootstrap-4

解决方案


不要在按钮中使用锚标记。对按钮使用 onClick。或者,您可以将锚设置为按钮:

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">

<button type="button" onclick="window.location='https://google.com'" class="btn btn-primary rounded-0">Google</button>

<a class="btn btn-primary rounded-0" href="https://google.com">Google</a>


推荐阅读