Spinner 主要用来输入各种格式的数字,可以使用鼠标滚轮,键盘方向键来修改输入值,也支持直接键入数字。支持本地化的输入金额和时间。
基本用法
下面代码显示了Spinner的基本用法,设置和取得Spinner的当前值。
4 | < meta charset = "utf-8" /> |
5 | < title >jQuery UI Demos</ title > |
6 | < link rel = "stylesheet" href = "themes/trontastic/jquery-ui.css" /> |
7 | < script src = "scripts/jquery-1.9.1.js" ></ script > |
8 | < script src = "scripts/jquery-ui-1.10.1.custom.js" ></ script > |
11 | var spinner = $("#spinner").spinner(); |
13 | $("#disable").click(function () { |
14 | if (spinner.spinner("option", "disabled")) { |
15 | spinner.spinner("enable"); |
17 | spinner.spinner("disable"); |
20 | $("#destroy").click(function () { |
21 | if (spinner.data("ui-spinner")) { |
22 | spinner.spinner("destroy"); |
27 | $("#getvalue").click(function () { |
28 | alert(spinner.spinner("value")); |
30 | $("#setvalue").click(function () { |
31 | spinner.spinner("value", 5); |
41 | < label for = "spinner" >Select a value:</ label > |
42 | < input id = "spinner" name = "value" /> |
46 | < button id = "disable" >Toggle disable/enable</ button > |
47 | < button id = "destroy" >Toggle widget</ button > |
51 | < button id = "getvalue" >Get value</ button > |
52 | < button id = "setvalue" >Set value to 5</ button > |

显示地图
本例使用两个Spinner,以步长为0.001 做为经纬度,然后和Google地图配合,通过Spinner修改地图的中心。
此外为了适应Google Map API,需要添加对其引用
代码如下:
4 | < meta charset = "utf-8" /> |
5 | < title >jQuery UI Demos</ title > |
6 | < link rel = "stylesheet" href = "themes/trontastic/jquery-ui.css" /> |
7 | < script src = "scripts/jquery-1.9.1.js" ></ script > |
8 | < script src = "scripts/jquery-ui-1.10.1.custom.js" ></ script > |
9 | < script src = "http://maps.google.com/maps/api/js?sensor=false" ></ script > |
13 | return new window.google.maps.LatLng($("#lat").val(), |
17 | map.setCenter(latlong()); |
19 | $("#lat, #lng").spinner({ |
25 | var map = new window.google.maps.Map($("#map")[0], { |
28 | mapTypeId: window.google.maps.MapTypeId.ROADMAP |
41 | < label for = "lat" >Latitude</ label > |
42 | < input id = "lat" name = "lat" value = "44.797" /> |
44 | < label for = "lng" >Longitude</ label > |
45 | < input id = "lng" name = "lng" value = "-93.278" /> |
