【jquery实现简易的输入法】jQuery实现简易的输入框字数计数功能示例

更新时间:2021-08-12    来源:jquery    手机版     字体:

【www.bbyears.com--jquery】

运行效果图如下:

具体代码如下:




  
  
  <script src="jquery-1.7.2.min.js"></script>



  

<script>
  $.fn.extend({
    wordCount:function(maxLength, wordWrapper) {
      varself =this;
      $(self).attr("maxlength", maxLength);
      showWordCount();
      $(this).on("input propertychange", showWordCount);
      functionshowWordCount() {
        curLength = $(self).val().length;
        varleaveCount = maxLength - curLength;
        wordWrapper.text(leaveCount +"/"+ maxLength);
      }
    }
  })
  $(function() {
    $("#abc").wordCount(10, $("#wordCountShow"));
  })
</script>

本文来源:http://www.bbyears.com/wangyezhizuo/135568.html

猜你感兴趣