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

使用時需引入 bootstrap-switch.css、jQuery 與 bootstrap-switch.js。
用 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 單選,還要處理切換時的互斥狀態,讓同一群組只會有一個作用中。