jQuery Character Counter使用类? [英] jQuery Character Counter using class?

查看:96
本文介绍了jQuery Character Counter使用类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很长的表格,其中包含textareas字段,我想使用类选择器而不是ID来标识字段和每个字段的限制.现在,我正在工作:

I have a rather long form with textareas fields and I'd like to use a class selector instead of an ID to identify the fields and limits for each field. Right now, I have this working:

$(document).ready(function(){
    $("#TextAreaID").counter({
        goal: 500
    });
});

这适用于一个文本区域,但是由于我有多个文本区域,因此我想知道一种更好的方法,因为这不起作用:

and this works for one textarea but since I have several textarea's, I'd like to know a better way to do this since this doesn't work:

$(document).ready(function(){
    $(".limit500").counter({
        goal: 500
    });
});

我正在使用以下jQuery插件: http://meetups. jquery.com/profiles/blogs/jquery-word-and-character

I'm using this jQuery Plugin: http://meetups.jquery.com/profiles/blogs/jquery-word-and-character

推荐答案

遍历元素并将.counter应用于每个元素:

Loop through the elements and apply .counter to each:

$(document).ready(function(){
    $(".limit500").each(function() {
        $(this).counter({
            goal: 500
        });
    });
});

这篇关于jQuery Character Counter使用类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆