2011-06-02 55 views
0

我可以弄清楚如何循环输入和选择。我的下面的功能不包括选择列表。无法从表单中获取<select>输入?

任何帮助欢迎。

$('input', '#consumer_form').each(function(key, value) 
{     
    if ((this.type === "radio" || this.type === "checkbox") && this.checked === false) { 
     return; 
    } else { 
     val = this.value; 
    } 

     //alert($('#'+this.id).attr('name')+'='+replaceAmp(val)); 
      formData += '&'+this.name+'='+replaceAmp(val); 

}); 

感谢

+0

选择是'select'元素,而不是'input'元素。 – BoltClock 2011-06-02 06:35:50

+0

你会介意发布你的HTML :)谢谢 – 2011-06-02 06:59:13

回答

0

使用jQuery你可以得到所有input,并通过这样选择elements

$('input, select') 

所以你需要做一些像

$('input, select').each(function(key, value) {     
    if ($(this).is('select')) do_select_stuff();    
    else if ($(this).is(':checkbox')) do_checkbox_stuff(); 
    else if ($(this).is(':radio')) do_radio_stuff(); 
}); 
0

尝试

$('input, select', '#consumer_form').each(function(key, value)