English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Button(Button) in Bootstrap Buttons It has been introduced in the first chapter. You can add some interactions through the Button plug-in, such as controlling the button status, or creating button groups for other components (such as toolbars).
To add a load state to the button, simply add data-loading-text="Loading..." as its attribute, as shown in the following example:
Test and see ‹/›Bootstrap 示例 - Button plug-in load state</title> <button id="fat-btn" class="btn btn-primary" data-loading-text="Loading..." type="button"> Load state </button> <script> $(function() { $(".btn").click(function(){ $.button('loading').delay(1000).queue(function() { // $(this).button('reset'); // $(this).dequeue(); }); }); }); </script> </body> </html>
The results are as follows:
To activate the toggle of a single button (i.e., change the normal state of the button to pressed state, and vice versa), simply add data-toggle="button" as its attribute, as shown in the following example:
Test and see ‹/›Bootstrap 示例 - Button plug-in single toggle</title>
The results are as follows:
You can create a checkbox group and pass it to btn-group Add data attributes data-toggle="buttons" to add the toggle of the checkbox group.
Test and see ‹/›Bootstrap 示例 - Button plug-in checkbox</title> <div class="btn-group" data-toggle="buttons"> <label class="btn btn-primary"> <input type="checkbox"> Options 1 </label> <label class="btn btn-primary"> <input type="checkbox"> Options 2 </label> <label class="btn btn-primary"> <input type="checkbox"> Options 3 </label> </div> </body> </html>
The results are as follows:
Similarly, you can create a radio button group and pass it to btn-group Add data attributes data-toggle="buttons" to add the toggle of the radio button group.
Test and see ‹/›Bootstrap 示例 - Button plug-in radio button</title> <div class="btn-group" data-toggle="buttons"> <label class="btn btn-primary"> <input type="radio" name="options" id="option1"> Options 1 </label> <label class="btn btn-primary"> <input type="radio" name="options" id="option2"> Options 2 </label> <label class="btn btn-primary"> <input type="radio" name="options" id="option3"> Options 3 </label> </div> </body> </html>
The results are as follows:
You can Through JavaScript Enable the Button plug-in as shown below:
$('.btn').button()
No options.
Here are some useful methods in the Button plug-in:
method | description | 示例 |
---|---|---|
button('toggle') | Toggle the pressed state. Give the button the appearance of being activated. You can use data-toggle The property enables the automatic toggle of the button. | $().button('toggle') |
.button('loading') | When loading, the button is disabled and the text becomes the text of the button element data-loading-text The value of the property. | $().button('loading') |
.button('reset') | 重置按钮状态,文本内容恢复为最初的内容。当您想要把按钮返回为原始的状态时,该方法非常有用。 | $().button('reset') |
.button(string) | 该方法中的字符串是指由用户声明的任何字符串。使用该方法,重置按钮状态,并添加新的内容。 | $().button(string) |
下面的示例演示了上面方法的用法:
Bootstrap 示例 - 按钮(Button)插件方法 点击每个按钮查看方法效果
演示 .button('toggle') 方法
</div>演示 .button('loading') 方法