jQuery Character Counter使用类? [英] jQuery Character Counter using class?
问题描述
我有一个很长的表格,其中包含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屋!