滑块(Slider) - 对齐增量
通过把 step
选项设置为一个整数来设置滑块值的增量,通常是滑块最大值的除数。默认增量是 1。
源代码
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>jQuery UI 滑块(Slider) - 对齐增量</title> <link rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css"> <script src="//code.jquery.com/jquery-1.9.1.js"></script> <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> <link rel="stylesheet" href="http://jqueryui.com/resources/demos/style.css"> <script> $(function() { $( "#slider" ).slider({ value:100, min: 0, max: 500, step: 50, slide: function( event, ui ) { $( "#amount" ).val( "$" + ui.value ); } }); $( "#amount" ).val( "$" + $( "#slider" ).slider( "value" ) ); }); </script> </head> <body> <p> <label for="amount">捐款金额($50 增量):</label> <input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;"> </p> <div id="slider"></div> </body> </html>