多くのフィールドセットでは、次のボタンを使用して、「#required」ID 入力があるかどうかを確認し、空の場合は false を返し (このフィールドセットにとどまる)、そうでない場合はアクションに進みます ...
if ($(this).attr('required').length == 0) {
alert ('oui');
if (!$(this).attr('required'))
return false;
}
else
alert ('non');
しかし、見つからないため$(this).attr('required').length
です。undefined
id
助けが必要です、すべてに感謝します。
説明します: フィールドセット (動的に作成された) で、ID #required の入力が存在する場合、それが空かどうかを確認する必要があります。そうである場合、ボタンをクリックすると false が返されます。私はフランス人で、jQuery は初めてなので、申し訳ありません =\
HTML :
[...]
<fieldset>
<h2 class="fs-title">Accueil Particulier</h2>
<h3 class="fs-subtitle">Nombre de personnes :</h3>
<input type="number" class="required" name="par_venu_f" placeholder="Femme(s)"/>
<input type="number" class="required" name="par_venu_h" placeholder="Homme(s)"/>
<br/><br/><input type="button" name="previous" class="previous action-button" value="Précédent"/>
<input type="button" name="next" class="next action-button" value="Suivant"/>
</fieldset>
[...]
編集 :
わかりました、今私はここにいます:
if ($(this).parent().children().hasClass('required')) {
if ($(this).parent().children('.required').val().length == 0) {
alert('find, empty')
return false;
};
alert ('find, full');
}
else alert ('not find');
大丈夫ですが、最初の入力[type = text]のみをチェックする場合、他の入力をチェックするにはどうすればよいですか?
EDIT 2: .each() 関数を試してみましたが、それがどのように機能するのかわかりません...
答え :
数分前にこれだけを見つけたとしても、@TrueBlueAussieに感謝します。
//check if class="required" exist
if ($(this).parent().children().hasClass('required')) {
//start of each class="required"
$(this).parent().children('.required').each(function() {
//if empty, do not continue
if ($(this).val().length == 0) {fill_required = false;};
//end each
});
// end if exist
};
// if there is one empty field, will be false so ...
if (!fill_required) {
// make it true before leave then ...
fill_required = true;
// leave.
return false;
//end if one empty
};