Giter Club home page Giter Club logo

jquery.chineselengthlimit's Introduction

jQuery Chinese Characters Length Limit Plugin

這是一個可以限制 文字框(input[type='text'])文字輸入區域(textarea) 輸入 中英文字數 的 jQuery Plugin。


Options

下面是可以調整的參數:

Options Description
limitCount 最大長度限制。預設值為 10
若目標對象有 maxlength 屬性,則以此數字限制。但若在 $( 元素 ).ChineseLengthLimit( opts ) 中有傳入字數限制,則以此設定為最優先。
isByte 是否採用位元限制。預設值為 true
若採用,則會以中文字以 2 字元、英文字以 1 字元的方式計算。
換行字元 (\n) 則一律計算為 2 字元。
callback 當 keyup 與 paste 事件觸發時,呼叫的 callback 事件。無預設 function。

使用範例:
callback: function (data) {
$("#msg").html("目前輸入:" + data.input + "/" + data.max + " 還剩:" + data.left + "字元");
}

回傳的物件中擁有三個屬性:
* input:目前輸入的字數,會依 isByte 的 true or false 而改變計算方式。
* max:最大限制的字數,會依 isByte 的 true or false 而改變計算方式。
* left:剩餘可輸入的字數,會依 isByte 的 true or false 而改變計算方式。

Usage

###Basic

$(function () { 
    $('目標對象').ChineseLengthLimit(); 
});

###Advanced

$(function () { 
    $('目標對象').ChineseLengthLimit({ 
       limitCount: 11, 
      isByte: true, 
      callback: function (data) { 
 	       $('顯示 callback 訊息元素').html("目前輸入:" + data.input + "/" + data.max + " 還剩:" + data.left + "字元"); 
      } 
   }); 
});

jquery.chineselengthlimit's People

Contributors

wild0522 avatar patw0929 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.