div内のすべての入力フィールドを見つけて数え、空のボタンがある場合はボタンを無効にしようとしています。ただし、同じクラスの div がいくつかあります。入力フィールドは 1 つだけ必要です。ダースのことを試しましたが、うまくいきません。ページ上のすべての入力フィールドをカウントするか、まったくカウントしません。
function submitDisable(){
counter = 0;
$('.shipdiv input').each(function(){
if( $(this).val() == ''){
$(this).css("background-color","#ff0000");
$(this).closest('.shipdiv').find('#button-submit').prop('disabled', true);
counter++;
}
if( $(this).val() != ''){
$(this).css("background-color","");
counter-1;
}
if(counter == "0"){
$(this).closest('.shipdiv').find('#button-submit').prop('disabled', false);
}
});
}
jQuery(document).ready(function(){
$('.shipdiv').click(submitDisable);
});
私は試しました:誰かが理解し、私を助けることができることを$(this, 'input')
願っています。ありがとう!find();
children();