Bootstrap按钮的href不起作用

7
请问为什么我的链接无法使用?

<!-- Optional theme  this one is ok -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap-theme.min.css" integrity="sha384-fLW2N01lMqjakBkx3l/M9EahuwpSfeNvV63J5ezn3uZzapT0u7EYsXMjQV+0En5r" crossorigin="anonymous">
<button type="button" class="btn btn-primary" href="#">Get your Free Quote now!</button>

3个回答

13
使用类名为buttons的

虽然问题是为什么href与按钮不起作用,但这是解决不起作用的href问题的更好方法。 - Kevz

9
您可以执行以下操作:它有效。
<a href="#"><button type="button" class="btn btn-primary">Get your Free Quote now!</button></a>

6

行内 JavaScript:

<button onclick="window.location='http://www.example.com';">Visit Page Now</button>

在Javascript中定义函数:

<script> function visitPage(){ window.location='http://www.example.com'; } </script> <button onclick="visitPage();">Visit Page Now</button>

或者在Jquery中。
<button id="some_id">Visit Page Now</button> $('#some_id').click(function() { window.location='http://www.example.com'; });

在Bootstrap中,
<button type="button" class="btn btn-primary" onclick="window.location='http://www.example.com';">Get your Free Quote now!</button>

这是一个好的答案。其他使用<a>标签的答案在技术上是可行的,但往往在Bootstrap中不同的浏览器会渲染得不理想。 - Milo Persic

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接