この質問は、クラスを使用した jQuery Character Counterの拡張ですか? .
テキストエリア フィールドに を追加し、data-content="####"
jQuery を使用して数値を取り出し、それを文字カウンター リミッターに適用したいと思います。
<textarea id="field1" class="input-xlarge limitChars" data-content="2000" rows="2" name="field1">
このフィールドには 2000 文字の制限があります
<textarea id="field2" class="input-xlarge limitChars" data-content="1000" rows="2" name="field2">
このフィールドには 1000 文字の制限があります
<textarea id="field3" class="input-xlarge limitChars" data-content="1500" rows="2" name="field3">
これは1500文字になります。
私の他の質問の解決策(以下の解決策を参照)から、DOMからデータコンテンツを引き出して、それを目標に適用する必要があると思います。データコンテンツから価値を引き出す方法がわからないので、助けていただければ幸いです。
$(document).ready(function(){
$(".limitChars").each(function() {
$(this).counter({
goal: 500
});
});
});
================================================== ===
拡張されたダイアログが表示されたので、実際に最終的にどうなったかを示すと役立つかもしれないと考えました。
HTML
<textarea id="field1" class="input-xlarge" counter-limit="2000" rows="2" name="field1"> this field would have a limit of 2000 chars
JavaScript/jQuery
$("[data-counter-limit]").each(function() {
var $this = $(this), limit = +$(this).data("counter-limit");
$this.counter({
goal: parseInt(limit,10)
// goal: limit
});
});