bootstrap按鈕插件(Button)使用方法解析
按鈕插件(Button)學(xué)習(xí)筆記:
按鈕插件
樣式文件:
☑ LESS版本:源文件buttons.less
☑ 點(diǎn)擊按鈕時(shí),按鈕文字變?yōu)椤罢诩虞d…”,一旦加載完之后又變回“獲取數(shù)據(jù)”。簡單點(diǎn)說就是控制按鈕狀態(tài),比如禁用狀態(tài)、正在加載狀態(tài)、正常狀態(tài)等;
☑ 按鈕切換狀態(tài)
☑ 按鈕模仿單選按鈕
☑ 按鈕模仿復(fù)選按鈕
按鈕插件–按鈕加載狀態(tài)
通過按鈕可以設(shè)計(jì)狀態(tài)提示,當(dāng)單擊按鈕時(shí),會(huì)顯示loading狀態(tài)信息。例如,點(diǎn)擊“加載”按鈕,會(huì)觸發(fā)按鈕的加載的狀態(tài)
加載
通過data-loading-text屬性定義加載的文本信息,然后通過JavaScript給按鈕綁定一個(gè)事件,并給按鈕添加一個(gè)button(“l(fā)oading”)方法來激活按鈕的加載狀態(tài)行為。如下所示:
$(function(){
$("#loaddingBtn").click(function () {
$(this).button("loading");
});
});
按鈕插件–模擬單選擇按鈕
在Bootstrap框架中按鈕插件中,可以通過給按鈕組自定義屬性data-toggle=”buttons”
<div class="btn-group"> <label class="btn btn-primary"> <input type="radio" name="options" id="options1">男 </label> <label class="btn btn-primary"> <input type="radio" name="options" id="options2">女 </label> <label class="btn btn-primary"> <input type="radio" name="options" id="options3">未知 </label> </div> ---------------------------------------------------------------------- <div class="btn-group" data-toggle="buttons"> <label class="btn btn-primary"> <input type="radio" name="options" id="options1">男 </label> <label class="btn btn-primary"> <input type="radio" name="options" id="options2">女 </label> <label class="btn btn-primary"> <input type="radio" name="options" id="options3">未知 </label> </div>
按鈕插件–模擬復(fù)選按鈕
<div class="btn-group"> <label class="btn btn-primary"> <input type="checkbox" name="options" id="options1">電影 </label> <label class="btn btn-primary"> <input type="checkbox" name="options" id="options2">音樂 </label> <label class="btn btn-primary"> <input type="checkbox" name="options" id="options3">游戲 </label> <label class="btn btn-primary"> <input type="checkbox" name="options" id="options4">攝影 </label> </div> ------------------------------------------------------------------- <div class="btn-group" data-toggle="buttons"> <label class="btn btn-primary"> <input type="checkbox" name="options" id="options1">電影 </label> <label class="btn btn-primary"> <input type="checkbox" name="options" id="options2">音樂 </label> <label class="btn btn-primary"> <input type="checkbox" name="options" id="options3">游戲 </label> <label class="btn btn-primary"> <input type="checkbox" name="options" id="options4">攝影 </label> </div>
按鈕插件–按鈕狀態(tài)切換
使用 data-toggle 屬性還可以激活按鈕的行為狀態(tài),實(shí)現(xiàn)在激活和未激活之間進(jìn)行狀態(tài)切換。
<button type="button" data-toggle="button" class="btn btn-primary">確認(rèn)</button>
按鈕插件–JavaScript用法
1、切換按鈕狀態(tài)(得到焦點(diǎn))
$("#mybutton").button("toggle")
2、重新恢復(fù)按鈕:
$("#mybutton").button("reset")
3、任意參數(shù):
$(“#mybutton”).button(“任意字符參數(shù)名”)
替換 data-任意字符參數(shù)名-text 的屬性值為“按鈕上顯示的文本值”
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
JavaScript使用簡單正則表達(dá)式的數(shù)據(jù)驗(yàn)證功能示例
這篇文章主要介紹了JavaScript使用簡單正則表達(dá)式的數(shù)據(jù)驗(yàn)證功能,結(jié)合實(shí)例形式分析了JS針對(duì)表單輸入內(nèi)容的簡單正則驗(yàn)證操作技巧,需要的朋友可以參考下2017-01-01
微信小程序wx.previewImage預(yù)覽圖片實(shí)例詳解
下面通過實(shí)例代碼給大家講解了微信小程序wx.previewImage預(yù)覽圖片功能,需要的朋友可以參考下2017-12-12
利用JavaScript腳本實(shí)現(xiàn)滾屏效果的方法
這篇文章主要介紹了利用JavaScript腳本實(shí)現(xiàn)滾屏效果的方法,即一個(gè)公告欄顯示般的效果,需要的朋友可以參考下2015-07-07
前端傳遞參數(shù)時(shí)form-data和json的區(qū)別詳解
前端可以通FormData對(duì)象實(shí)現(xiàn)表單形式提交數(shù)據(jù),下面這篇文章主要給大家介紹了關(guān)于前端傳遞參數(shù)時(shí)form-data和json區(qū)別的相關(guān)資料,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-11-11
url特殊字符編碼encodeURI?VS?encodeURIComponent分析
這篇文章主要介紹了url特殊字符編碼encodeURI?VS?encodeURIComponent分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-09-09

