我有一个有很多选择的表单.
在发送表单之前,我需要检查所有select是否都有选项值.
我有它,但没有成功:
$('#myForm').submit(function() {
$("#myForm select:selected").each(function(index){
alert(index + ': ' + $(this).val());
});
});
Run Code Online (Sandbox Code Playgroud)
怎么样?
尝试使用:
$("#myForm select").each(function(index){
if ($(this).has('option:selected')){
alert('Select number ' + index + ': ' + $(this).val());
}
});
Run Code Online (Sandbox Code Playgroud)