这是一款jquery数字加减输入框插件。该插件兼容bootstrap框架,可以将普通的input转换为类似商城购物车中的数量加减器效果。
使用方法
在页面中引入jquery和jquery.input-counter.min.js文件。
<script src="js/jquery.min.js"></script>
<script src="js/jquery.input-counter.min.js"></script>                    
                
                HTML结构
该jquery数字加减输入框的基本HTML结构如下。
<div class="example">
  <button type="button" class="btn-add">
    +
  </button>
  <input type="text" class="input-counter">
  <button type="button" class="btn-subtract">
    -
  </button>
  </div>
</div>
                
                通过data属性可以设置数字的默认值,最大值和最小值。
<input type="text" 
       class="input-counter" 
       data-min="10" 
       data-max="100" 
       data-default="20"
>
                
                初始化插件
在页面DOM元素加完毕之后,通过下面的方法来初始化该插件。
$(".example").inputCounter();              
                
                你也可以在指定的CSS选择器。
$(".example").inputCounter({
  selectors: {
    addButtonSelector: '.btn-add',
    subtractButtonSelector: '.btn-subtract',
    inputSelector: '.input-counter',
  }
}); 
                
                配置参数
$(".example").inputCounter({
  settings: {
    // check the valus is within the min and max values
    checkValue: true, 
    // is read only?
    isReadOnly: true
    
  }
});           
                
                checkValue:是否检查数字在指定范围内。
isReadOnly:是否只读。
该jquery数字加减输入框插件的github地址为:https://github.com/lk-code/jquery-input-counter
版权声明
文章来源: https://www.uihtm.com/jquery/9766.html
版权说明:仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负。我们非常重视版权问题,如有侵权请邮件(44784009#qq.com)与我们联系处理。敬请谅解!


                    



















