使用类的jQuery字符计数器?

我有一个相当长的textareas字段forms,我想使用类选择器而不是ID来识别每个字段的字段和限制。 现在,我有这个工作:

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

这适用于一个textarea,但由于我有几个textarea,我想知道一个更好的方法来做到这一点,因为这不起作用:

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

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

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

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

您应该能够将counter()应用于每个元素(完全未经测试) –

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