select表单序列化serialize()出现问题

来源:互联网 发布:管理学网络计划图例题 编辑:程序博客网 时间:2024/05/21 11:25

今天在序列化select时,遇到了一个问题
HTML:

    <input name="id" type="text"/>    <select class="form-control" id="placeSelect" name="place">        <option  value="1">1</option>        <option  value="2">2</option>        <option  value="3">3</option>    </select>

原来的做法:

    alert($('select>option:selected').serialize())//''    alert(typeof 'select>option:selected').serialize();//string

之后尝试了这种,就好了:

    alert($('select').serialize());//place=1    alert(typeof $('select').serialize());//string

同理:

alert($('input,select>option:selected').serializeArray());//[object Object]    alert(JSON.stringify($('input,select>option:selected').serializeArray()));//[{"name":"id","value":""}]alert($('input,select').serializeArray());//[object Object],[object Object]    alert(JSON.stringify($('input,select').serializeArray()));//[{"name":"id","value":""},{"name":"place","value":"1"}]
阅读全文
0 0
原创粉丝点击