form表单转换为Json数据
最近对前端js学习有点多,如今想自己动手写点插件,后来发现,我想到的,其他人都想到了。于是做了以下笔记。
使用插件:
插件 :https://github.com/marioizquierdo/jquery.serializeJSON
调用方式:
console.log($('form[name="formEdit"]').serializeJSON());
HTML代码:
1 <div class="box"> 2 <div class="content"> 3 <form name="formEdit" method="post"> 4 <input name="id" value="1" type="text" /><br /> 5 <input name="name" value="jeamy" type="text" /><br /> 6 <input name="age" value="28" type="number" /> <br /> 7 <input name="sex2" type="checkbox" checked="checked" />男 <br /> 8 <input name="sex1" type="checkbox" checked="checked" />女 <br/> 9 <textarea name="intro" cols="5" >dasdfasdtextarea> <br/> 10 <select name="city"> 11 <option value ="1">武汉option> 12 <option value ="2">北京option> 13 <option value ="3">纽约option> 14 select><br/> 15 <label><input name="Fruit" type="radio" value="1" checked/>苹果 label> 16 <label><input name="Fruit" type="radio" value="2" />桃子 label> 17 <label><input name="Fruit" type="radio" value="3" />香蕉 label> 18 <label><input name="Fruit" type="radio" value="4" />梨 label> 19 <label><input name="Fruit" type="radio" value="5" />其它 label> 20 <div> 21 <input type="button" onclick="getinfo();" value="提交" /> 22 div> 23 form> 24 div> 25 div>