baozhengrui

导航

序列化form表单

Ajax 提交表单数据


  <form id= "userForm" >
      <input type="text" name="username" value="123">
      <input type="text" name= "password" value="abc">
  </form>

1.serialize()


$('#userForm').serialize();  //   "username="123&password="abc"
 

2.serializeArray() --返回对象数组


$("#userForm").serializeArray();
//[{name: "username",value: "123"},{name:'passward', value: "abc"}]

3.serializeObject() --返回对象


let array = $("#userForm").serializeArray();
for( let i = 0; i < array.length; i++ ){
  file.append(array[i].name, array[i].value);  // 变为json对象格式
}
//{username: "123", passward: "abc"}


$('#userForm").serializeObject();
//{username: "123", passward: "abc"}


posted on 2022-06-10 14:59  芮艺  阅读(22)  评论(0编辑  收藏  举报