无线电输入上的Bootstrap工具提示

时间:2016-07-07 18:33:06

标签: javascript twitter-bootstrap input radio-button tooltip

此代码不起作用。也可以在没有JS的情况下尝试将属性放入<input>。似乎没什么用。

$('#radio1').tooltip({
    placement: "bottom",
    trigger: "hover"
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<div class="btn-group" data-toggle="buttons">

    <label class="btn btn-primary active">
        <input type="radio" name="options" id="radio1" autocomplete="off" 
            data-toggle="tooltip" title="tooltip on radio!">Radio 1
    </label>

    <label class="btn btn-primary">
        <input type="radio" name="options" id="radio2" autocomplete="off">Radio 2
    </label>

</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

1 个答案:

答案 0 :(得分:2)

尝试将工具提示的属性应用于<label>

$(function () {
  $('[data-toggle="tooltip"]').tooltip()
})
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">

<div class="btn-group" data-toggle="buttons">

  <label class="btn btn-primary active" data-toggle="tooltip" data-placement="bottom" title="tooltip on radio!">
    <input type="radio" name="options" id="radio1" autocomplete="off">Radio 1
  </label>

  <label class="btn btn-primary">
    <input type="radio" name="options" id="radio2" autocomplete="off">Radio 2
  </label>

</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>