遍歷表單所有資料轉JSON格式
阿新 • • 發佈:2018-12-30
<form method="post" action="javascript:void(0);" onsubmit="getElements()" id="freezhaobiao" class="signUpbox"> <ul class="signUp"> <li class="intro">title1</li> <li class="desTit">title2</li> <!--<li class="desType">型別:<input value="1" name="type" checked="checked" onclick="$('.desTit').html('免費釋出裝修招標');" id="zxType1" type="radio"><label for="zxType1">免費設計</label>--> <!--<input value="2" name="type" id="zxType2" onclick="$('.desTit').html('免費釋出設計招標');" type="radio"><label for="zxType2">收費設計</label>--> <!--</li>--> <li><em>* </em>:<input type="text" class="price_sign" id="price" name="price" placeholder="請填寫您的東西" /></li> <li><em>* </em>name:<input type="text" class="name_sign" id="chenghu" name="chenghu" placeholder="請填寫您的名字"></li> <li><em>* </em>phone:<input type="text" class="tel_sign" id="phone" name="phone" placeholder="請填寫您的聯絡方式"></li> </ul> </form> <script> function getElements() { var params = $('#freezhaobiao').serializeArray(); var values = {}; for( x in params ){ values[params[x].name] = params[x].value; } var idata = JSON.stringify(values) console.log(idata); } </script>