遍历表单所有数据转JSON格式

<form method="post" action="javascript:void(0);" οnsubmit="getElements()" id="freezhaobiao"
      class="signUpbox">
    <ul class="signUp">
        <li class="intro">title1li>
        <li class="desTit">title2li>
        
        
        
        <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>

你可能感兴趣的:(遍历表单所有数据转JSON格式)