标签:
来源: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="jsmith@example.com"> <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":"jsmith@example.com","pets":["cat","dog"]}} </script>
标签:
原文地址:http://www.cnblogs.com/yjhua/p/4615146.html