【问题标题】:bootstrap button href does not work引导按钮 href 不起作用
【发布时间】:2016-06-19 08:47:24
【问题描述】:

谁能解释一下为什么我的链接不起作用?

<!-- 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">
&lt;button type="button" class="btn btn-primary" href="#"&gt;Get your Free Quote now!&lt;/button&gt;

【问题讨论】:

    标签: button href


    【解决方案1】:

    正确的做法是使用按钮类。

    <a href="https://www.google.com" class="btn btn-primary">Get your Free Quote now!</a>
    

    小提琴示例:

    https://jsfiddle.net/aq9Laaew/159899/

    【讨论】:

    • 虽然问题是为什么它的 href 不适用于按钮,但这是解决 href 不起作用问题的更好方法。
    【解决方案2】:

    您可以执行以下操作:它有效。

    <a href="#"><button type="button" class="btn btn-primary">Get your Free Quote now!</button></a>
    

    按钮的设计风格保持不变。

    【讨论】:

      【解决方案3】:

      内联 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'; });
      

      在引导中,

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

      【讨论】:

        猜你喜欢
        • 2016-03-20
        • 2012-09-03
        • 2018-02-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-07-12
        • 2015-10-12
        相关资源
        最近更新 更多