jQuery Mobile 表單滑動條
jQuery Mobile 滑動條控件
滑動條可讓您從一個範圍的數字中選擇一個值:
如需建立滑動條,請使用 <input type="range">:
實例
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page"> <div data-role="header"> <h1>滑块控件</h1> </div> <div data-role="main" class="ui-content"> <form method="post" action="demoform.asp"> <label for="points">进度:</label> <input type="range" name="points" id="points" value="50" min="0" max="100"> <input type="submit" data-inline="true" value="提交"> </form> </div> </div> </body> </html>
執行實例 »
點擊 "運行實例" 按鈕查看線上實例
使用下列屬性來規定限制:
-
max - 規定允許的最大值
-
min - 規定允許的最小值
-
step - 規定合法的數字間隔
-
值 - 規定預設值
提示: 如果你想在按鈕中顯示進度的值可以加 data-show-value="true" 屬性:
實例
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page"> <div data-role="header"> <h1>滑块控件</h1> </div> <div data-role="main" class="ui-content"> <form method="post" action="demoform.asp"> <label for="points">进度:</label> <input type="range" name="points" id="points" value="50" min="0" max="100" data-show-value="true"> <input type="submit" data-inline="true" value="提交"> </form> </div> </div> </body> </html>
執行實例 »
點擊 "運行實例" 按鈕查看線上實例
提示: 如果你想在滑動按鈕上顯示進度(類似一個小彈跳窗)可以使用 data-popup-enabled="true" 屬性:
實例
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page"> <div data-role="header"> <h1>滑块控件</h1> </div> <div data-role="main" class="ui-content"> <form method="post" action="demoform.php"> <label for="points">进度:</label> <input type="range" name="points" id="points" value="50" min="0" max="100" data-popup-enabled="true"> <input type="submit" data-inline="true" value="提交"> </form> </div> </div> </body> </html>
執行實例 »
點擊 "運行實例" 按鈕查看線上實例
提示:如果您想要高亮突出顯示滑動條的值,請新增 data-highlight="true":
實例
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page"> <div data-role="header"> <h1>滑块控件</h1> </div> <div data-role="main" class="ui-content"> <form method="post" action="demoform.php"> <label for="points">进度:</label> <input type="range" name="points" id="points" value="50" min="0" max="100" data-popup-enabled="true"> <input type="submit" data-inline="true" value="提交"> </form> </div> </div> </body> </html>
執行實例 »
點擊 "運行實例" 按鈕查看線上實例
撥動開關
波動開關通常用於 on/off 或 true/false 按鈕:
我們可以使用 <input type="checkbox"> 元素並指定 data-role 為 "flipswitch" 來建立開關:
實例
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page"> <div data-role="main" class="ui-content"> <form method="post" action="demoform.php"> <label for="switch">切换开关:</label> <input type="checkbox" data-role="flipswitch" name="switch" id="switch"> <br> <input type="submit" data-inline="true" value="提交"> </form> </div> </div> </body> </html>
執行實例 »
點擊 "運行實例" 按鈕查看線上實例
預設情況下,開關切換的文字為 "On" 和 "Off"。你可以使用 data-on-text 和 data-off-text 屬性來修改它:
實例
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page"> <div data-role="main" class="ui-content"> <form method="post" action="demoform.php"> <label for="switch">切换开关:</label> <input type="checkbox" data-role="flipswitch" name="switch" id="switch" data-on-text="True" data-off-text="False"> <br> <input type="submit" data-inline="true" value="提交"> </form> </div> </div> </body> </html>
執行實例 »
點擊 "運行實例" 按鈕查看線上實例
提示:開關複選框可以使用 "checked" 屬性來設定預設的選項:
實例
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page"> <div data-role="main" class="ui-content"> <form method="post" action="demoform.asp"> <label for="switch">切换开关:</label> <input type="checkbox" data-role="flipswitch" name="switch" id="switch" checked> <br> <input type="submit" data-inline="true" value="提交"> </form> </div> </div> </body> </html>
執行實例 »
點擊 "運行實例" 按鈕查看線上實例
更多實例
區間滑桿
實例
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> </head> <body> <div data-role="page"> <div data-role="header"> <h1>区间滑块</h1> </div> <div data-role="main" class="ui-content"> <form method="post" action="demoform.asp"> <div data-role="rangeslider"> <label for="price-min">价格:</label> <input type="range" name="price-min" id="price-min" value="200" min="0" max="1000"> <label for="price-max">价格:</label> <input type="range" name="price-max" id="price-max" value="800" min="0" max="1000"> </div> <input type="submit" data-inline="true" value="Submit"> <p>区间滑块让用户选择指定区间的价格。</p> </form> </div> </div> </body> </html>
執行實例 »
點擊 "運行實例" 按鈕查看線上實例
製作一個區間值的滑桿。
滑桿樣式
實例
<!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.css"> <script src="http://apps.bdimg.com/libs/jquery/1.10.2/jquery.min.js"></script> <script src="http://apps.bdimg.com/libs/jquerymobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <style> /* Custom indentations are needed because the length of custom labels differs from the length of the standard labels */ .custom-size-flipswitch.ui-flipswitch .ui-btn.ui-flipswitch-on { text-indent: -4em; } .custom-size-flipswitch.ui-flipswitch .ui-flipswitch-off { text-indent: 2em; } /* Custom widths are needed because the length of custom labels differs from the length of the standard labels */ .custom-size-flipswitch.ui-flipswitch { width: 8.875em; } .custom-size-flipswitch.ui-flipswitch.ui-flipswitch-active { padding-left: 7em; width: 1.875em; } </style> </head> <body> <div data-role="page"> <div data-role="main" class="ui-content"> <form method="post" action="demoform.php"> <label for="switch">切换开关:</label> <input type="checkbox" data-role="flipswitch" name="switch" id="switch" data-wrapper-class="custom-size-flipswitch"> <br> <input type="submit" data-inline="true" value="提交"> </form> </div> </div> </body> </html>
執行實例 »
點擊 "運行實例" 按鈕查看線上實例
為滑塊開關設定樣式。