我有一个选择框,当从另一个选择框中选择一个选项时会填充该框。现在我希望在单击选项时发送 AJAX 调用。当单击事件绑定到选择框时,即使未单击选项,即即使我检查了所有选项,它也会发送 ajax。
$('#supname').click(function() {
    $('#gsm,#width,#type,#weight').empty();
    if($('#supname option').is(':selected')) { 
        $.post('<?php echo base_url()."index.php/inventory/getreeldata4supplier"; ?>'
            ,{supcode:$('#supname :selected').val(),reelno:$('#reelno').val(),date:$('#gidate').val()}
            , function(data){   
                if(data[0].count==0) {
                    alert('No reel entered on or before issue date');
                }
                else {
                    $.each(data,function(k,v){ 
                        $('#gsm').val(v.gsm);
                        $('#width').val(v.width);
                        $('#type').val(v.type);
                        $('#weight').val(v.weight);
                    })
                }
        },'json'  );
    }
 });
supname 是选择框的 id。如果未明确单击选项,即如果我检查选项,我不希望发送 AJAX。感谢您的每一次努力。