如何在表单中的每个选择中获取所选值?

bah*_*100 1 forms jquery

我有一个有很多选择的表单.

在发送表单之前,我需要检查所有select是否都有选项值.

我有它,但没有成功:

$('#myForm').submit(function() {

 $("#myForm select:selected").each(function(index){ 
   alert(index + ': ' + $(this).val()); 
 }); 

});
Run Code Online (Sandbox Code Playgroud)

怎么样?

Dav*_*mas 5

尝试使用:

$("#myForm select").each(function(index){
    if ($(this).has('option:selected')){
        alert('Select number ' + index + ': ' + $(this).val());
    }
});
Run Code Online (Sandbox Code Playgroud)