Jquery 如何在表单中的每个select中获取所选值?
我有一张有很多选择的表格 在发送表单之前,我需要检查所有select是否都有一个选项值 我有,但没有成功:Jquery 如何在表单中的每个select中获取所选值?,jquery,forms,Jquery,Forms,我有一张有很多选择的表格 在发送表单之前,我需要检查所有select是否都有一个选项值 我有,但没有成功: $('#myForm').submit(function() { $("#myForm select:selected").each(function(index){ alert(index + ': ' + $(this).val()); }); }); 怎么做?你必须这样做: $("#myForm select:selected").each(function(i
$('#myForm').submit(function() {
$("#myForm select:selected").each(function(index){
alert(index + ': ' + $(this).val());
});
});
怎么做?你必须这样做:
$("#myForm select:selected").each(function(index){
alert(index + ': ' + $(this).val());
});
这将提醒myForm中select的所有选定值。您必须这样做:
$("#myForm select:selected").each(function(index){
alert(index + ': ' + $(this).val());
});
var valid = $("select #myForm").filter(function(index){
return !$(this).val();
}).length == 0;
alert(valid)
这将提醒myForm中select的所有选定值。尝试使用:
var valid = $("select #myForm").filter(function(index){
return !$(this).val();
}).length == 0;
alert(valid)
$("#myForm select").each(function(index){
if ($(this).has('option:selected')){
alert('Select number ' + index + ': ' + $(this).val());
}
});
尝试使用:
$("#myForm select").each(function(index){
if ($(this).has('option:selected')){
alert('Select number ' + index + ': ' + $(this).val());
}
});
向我们展示您的html代码,因为如果看不到它,就有点难以确定最佳选择器!向我们展示您的html代码,因为如果看不到它,就有点难以确定最佳选择器!