0

私は長いフォームを持っているので、内部にデータがある入力とテキストエリアの数を数える必要があります。フォーム内にデータがある入力とテキストエリアの数を表す数値を表示する入力フィールドが必要です。

私はjqueryまたはPHPが好きです。

そこに例や提案はありますか?

ありがとう。エリック

4

3 に答える 3

1

jQueryを使用すると、これを使用できます

var number = $('#form').find('input, textarea')
                       // filter out every empty input/textarea
                       .filter(function() { return $(this).val() == ''; })
                       .length;
于 2012-04-18T14:18:03.377 に答える
1

データを持つフィールドの数でdivを実行および更新するonkeypress関数を実行できます。

私の頭の上からですが、多分:

function tallyFields() {

var totalFilledFields = 0;
var fieldAVal = document.getElementByID("fieldA").value;
// add more fields here the same way

if(fieldAVal.length > 0) {
 totalFilledFields++;
}
// check more fields here the same way and increment the same var

document.getElementByID("yourTotalDiv").innerHTML=totalFilledFields;

}

各フォームフィールドのキープレスでこの関数を割り当てると、うまくいく可能性があります。

于 2012-04-18T14:26:23.980 に答える
0

これでうまくいくはずです:

$(".myform :input").length;
于 2012-04-18T14:19:57.260 に答える