基於jQuery的Spin Button自訂文字框數值自增或自減_jquery

來源:互聯網
上載者:User
有時候在設計表單時需要對文字框實現數值自增或自減功能,例如預設為1,點擊向上按鈕鍵則增加指定步長值,點擊向下按鈕鍵則減少指定步長值,使用jQuery外掛程式jQuery Spin Button只需要幾行代碼就可實現該功能,效果如下圖

使用說明
一,需要使用jQuery庫檔案和jQuery Spin Button庫檔案(目前版本1.1.1)

素材準備
上下按鈕圖片,預設路徑為:/img/spin/,上下按鈕圖片命名為:spin-button.png,可進行自訂修改

執行個體代碼
一,包含檔案部分
複製代碼 代碼如下:

<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="jquery.spin.js"></script>

二,HTML部分(自訂文字框)
複製代碼 代碼如下:

<input type="text" id="number" value="0" />

三,javascript部分(jQuery外掛程式jQuery Spin Butt調用)
複製代碼 代碼如下:

<script type="text/javascript">
$(document).ready(function(){
$('#number').spin();
});
</script>

由上可知,使用jQuery外掛程式jQuery Spin Button自訂文字框數值自增或自減非常簡單,只需要設定好按鈕圖片,數值的初始值,就可實現自訂文字框數值自增或自減功能。

四,使用者自訂配置
imageBasePath: '/img/spin/',按鈕圖片路徑
spinBtnImage: 'spin-button.png',圖片按鈕圖片名
spinUpImage: 'spin-up.png', 向上自增按鈕圖片名
spinDownImage: 'spin-down.png', 向下自減按鈕圖片名
interval: 1,步長值
max: null, 最大值
min: null, 最小值
timeInterval: 500, 點擊時間間隔
timeBlink: 200 點擊閃爍時間

1,自訂步長值為10(代碼同上javascript部分)
$('#number').spin({interval:10});

2,自訂最大值與最小值
$('#number').spin({max:100,min: -100});

3,自訂按鈕圖片路徑
$('#number').spin({imageBasePath: '/images/'});

jQuery外掛程式jQuery Spin Button自訂配置對於定製個人化的文字框數值自增自減功能非常方便,使用也非常簡單,總的來說,自訂文字框數值自增或自減使用jQuery外掛程式jQuery Spin Button一行代碼輕鬆搞定。
查看示範:http://demo.jb51.net/js/jquery-spin/index.html

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.