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" >dasdfasd</textarea> <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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM