来源:https://github.com/macek/jquery-serialize-object
请看 文件里面的jquery-serialize-object-master.zip
有一个文件:jquery.serialize-object.js , 是用来 把表单 数据 进行JSON 格式。
用法:
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> </head> <script type="text/javascript" src="js/jquery-1.11.1.min.js"></script> <script type="text/javascript" src="js/jquery.serialize-object.js"></script> <body> <form id="contact"> <input name="user[email]" value="[email protected]"> <input name="user[pets][]" type="checkbox" value="cat" checked> <input name="user[pets][]" type="checkbox" value="dog" checked> <input name="user[pets][]" type="checkbox" value="bird"> <input type="submit"> </form> </body> </html> <script type="text/javascript"> var o= $(‘form#contact‘).serializeJSON(); console.log(o) //{"user":{"email":"[email protected]","pets":["cat","dog"]}} </script>
时间: 2024-12-20 01:19:10