- jQuery Mobile - Home
- jQuery Mobile - Overview
- jQuery Mobile - Setup
- jQuery Mobile - Pages
- jQuery Mobile - Icons
- jQuery Mobile - Transitions
- jQuery Mobile - Layouts
- jQuery Mobile - Widgets
- jQuery Mobile - Events
- jQuery Mobile - Forms
- jQuery Mobile - Themes
- jQuery Mobile - CSS Classes
- jQuery Mobile - Data Attributes
jQuery Mobile - Flip Switch Widget
Description
Flip Switch allows you to turn off/on or true/false the switch by clicking it for boolean style input.
Example
Following example demonstrates the use of flipswitch widget in the jQuery Mobile.
<!DOCTYPE html>
<html>
<head>
<meta name = "viewport" content = "width = device-width, initial-scale = 1">
<link rel = "stylesheet" href = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css">
<script src = "https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src = "https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script>
</head>
<body>
<form>
<h2>Flip Switch Examples</h2>
<h3>Basic Flipswitch</h3>
<input type = "checkbox" data-role = "flipswitch">
<h3>Basic checkbox switch with custom labels</h3>
<input type = "checkbox" data-role = "flipswitch" data-on-text = "YES"
data-off-text = "NO" data-wrapper-class = "custom-label-flipswitch" />
<h3>Basic checkbox switch with custom labels and custom size</h3>
<input type = "checkbox" data-role = "flipswitch" data-on-text = "Yes"
data-off-text = "No" data-wrapper-class = "custom-size-flipswitch" />
<h3>Basic checkbox switch checked</h3>
<input type = "checkbox" data-role = "flipswitch" checked = "" />
<h3>Basic select switch</h3>
<select data-role = "flipswitch">
<option>Off</option>
<option>On</option>
</select>
<h3>Basic select switch second option selected</h3>
<select id = "flip-select-second" name = "flip-select" data-role = "flipswitch">
<option>Off</option>
<option selected = "">On</option>
</select>
<h3>Theme</h3>
<input type = "checkbox" data-role = "flipswitch" data-theme = "b" />
<h3>Mini</h3>
<input type = "checkbox" data-role = "flipswitch" data-mini = "true" />
<h3>No corners</h3>
<input type = "checkbox" data-role = "flipswitch" data-corners = "false" />
<h3>Disabled</h3>
<input type = "checkbox" data-role = "flipswitch" disabled = "disabled" />
<h3>Label hidden</h3>
<label class = "ui-hidden-accessible">Flip toggle switch:</label>
<input type = "checkbox" data-role = "flipswitch" />
<h3>Fieldcontain</h3>
<div class = "ui-field-contain">
<label>Flip Contain:</label>
<select data-role = "flipswitch">
<option value = "off">Off</option>
<option value = "on">On</option>
</select>
</div>
<h3>Fieldcontain, mini</h3>
<div class = "ui-field-contain">
<label>Flip toggle switch:</label>
<select data-role = "flipswitch" data-mini = "true">
<option value = "off">Off</option>
<option value = "on">On</option>
</select>
</div>
</form>
</body>
</html>
Output
Let's carry out the following steps to see how the above code works −
Save the above html code as flipswitch_basic.html file in your server root folder.
Open this HTML file as http://localhost/flipswitch_basic.html and the following output will be displayed.
jquery_mobile_widgets.htm
Advertisements