Build jQuery UI Spinner - Default functionality in JavaScript
Description
The following code shows how to build jQuery UI Spinner - Default functionality.
Example
<!-- Revised from demo code on http://jqueryui.com/ -->
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Spinner - Default functionality</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<!--from w w w.ja va 2 s .c o m-->
<script>
$(function() {
var spinner = $( "#spinner" ).spinner();
$( "#disable" ).click(function() {
if ( spinner.spinner( "option", "disabled" ) ) {
spinner.spinner( "enable" );
} else {
spinner.spinner( "disable" );
}
});
$( "#destroy" ).click(function() {
if ( spinner.data( "ui-spinner" ) ) {
spinner.spinner( "destroy" );
} else {
spinner.spinner();
}
});
$( "#getvalue" ).click(function() {
alert( spinner.spinner( "value" ) );
});
$( "#setvalue" ).click(function() {
spinner.spinner( "value", 5 );
});
$( "button" ).button();
});
</script>
</head>
<body>
<p>
<label for="spinner">Select a value:</label>
<input id="spinner" name="value">
</p>
<p>
<button id="disable">Toggle disable/enable</button>
<button id="destroy">Toggle widget</button>
</p>
<p>
<button id="getvalue">Get value</button>
<button id="setvalue">Set value to 5</button>
</p>
<div class="demo-description">
<p>Default spinner.</p>
</div>
</body>
</html>
The code above generates the following result.
Javascript Tutorial Spinner
Build jQuery UI Spinner - Currency in JavaS...
Build jQuery UI Spinner - Decimal in JavaSc...
Build jQuery UI Spinner - Overflow in JavaS...
Build jQuery UI Spinner - Time in JavaScrip...
Build jQuery UI Spinner - Currency in JavaS...
Build jQuery UI Spinner - Decimal in JavaSc...
Build jQuery UI Spinner - Default functiona...
Build jQuery UI Spinner - Map in JavaScriptBuild jQuery UI Spinner - Overflow in JavaS...
Build jQuery UI Spinner - Time in JavaScrip...