Hot to get all form elements values using jQuery?

后端 未结 9 1703
谎友^
谎友^ 2020-12-22 23:45

Here is the HTML code:



    HTML Form Builder         


        
9条回答
  •  天涯浪人
    2020-12-23 00:16

    I needed to get the form data as some sort of object. I used this:

    $('#preview_form').serializeArray().reduce((function(acc, val) {
      acc[val.name.replace('[', '_').replace(']', '')] = val.value;
      return acc;
    }), {});
    

提交回复
热议问题