---
title: "Bootstrap-maxlength 使用"
author: "pako"
date: "2013-09-08T16:49:27Z"
tags: []
categories: ["Web前端"]
slug: "bootstrap-maxlength"
draft: false
lastmod: "2013-09-08T16:49:27Z"
id: 1938784
url: "https://pako.iteye.com/blog/1938784"
---

Demo：[http://mimo84.github.io/bootstrap-maxlength/](http://mimo84.github.io/bootstrap-maxlength/)

 

用法

1 给页面上的 input 或者 textarea 标签加上maxlenght 属性

```
<input type="text" name="nickname" maxlength="20" id="nickname">
```

 

2配置一些选项

```
    <script type="text/javascript" >
    $(document).ready(function(){
    $('input#defaultconfig').maxlength()
        $('input#nickname').maxlength({
        alwaysShow: true,
        });

        $('textarea#msg').maxlength({
        alwaysShow: true
        });

    });
    </script>
```

 

3别忘记引入 js文件  jquery 需要1.9以上版本

 

```
    <script src="/static/js/bootstrap-maxlength.js"></script>
    <script src="/static/js/bootstrap-maxlength.min.js"></script>

```

![](http://dl2.iteye.com/upload/attachment/0089/1003/dcf294d3-6eea-3079-94c3-1503cfdfcd1f.jpg)  
 

最后效果图

 

当然还有很多选项可以配置见  插件主页