DIV CSS 佈局教程網

Bootstrap Switch 開關控件
編輯:關於JavaScript     

Bootstrap Switch 可以把普通核取方塊變成滑動式開關,很適合設定頁或行動裝置介面。

引入資源

使用時需引入 bootstrap-switch.css、jQuery 與 bootstrap-switch.js。

基本 HTML

用 div.make-switch 包住 input checkbox,再用 data-on 與 data-off 指定開啟與關閉狀態的樣式。

初始化

$("div[class='switch']").each(function () {
  var $this = $(this);
  var $switch_input = $(" :only-child", $this);

  $switch_input.bootstrapSwitch({
    onColor: $this.attr("onColor"),
    offColor: $this.attr("offColor"),
    onText: $this.attr("onText"),
    offText: $this.attr("offText"),
    labelText: $this.attr("labelText")
  });
});

若使用 radio 單選,還要處理切換時的互斥狀態,讓同一群組只會有一個作用中。

XML學習教程| jQuery入門知識| AJAX入門| Dreamweaver教程| Fireworks入門知識| SEO技巧| SEO優化集錦|
Copyright © DIV+CSS佈局教程網 All Rights Reserved