jquery how to get form element types, names and values

前端 未结 5 1627
失恋的感觉
失恋的感觉 2020-12-30 07:34

I know I can get the name/value relationship by using

$(#form).serializeArray();

But is there a way to get the whole enchilada, type, name

5条回答
  •  鱼传尺愫
    2020-12-30 08:03

    Perhaps children() will be more useful but you'll still have to filter elements of interest yourself, unless you use a selector.

    You might also do the following if you only want to select successful elements in the form; this will NOT include buttons or disabled fields.

    $($('#testf').serializeArray()).each(function(index, value){
        $('#testf [name="' + value.name + '"]'); //select the named element
    });
    

    Mark's answer seems like the best way, IMO.

提交回复
热议问题