返回的JSON对象是由一个对象数组组成的,其中每个对象包含一个或两个名值对——name参数和value参数(如果value不为空的话)。举例来说:
[ {name: 'firstname', value: 'Hello'}, {name: 'lastname', value: 'World'}, {name: 'alias'}, // this one was empty ]示例:
取得表单内容并插入到网页中。
HTML 代码: <p><b>Results:</b> </p> <form> <select> <option>Single</option> <option>Single2</option> </select> <select multiple="multiple"> <option selected="selected">Multiple</option> <option>Multiple2</option> <option selected="selected">Multiple3</option> </select><br/> <input type="checkbox" value="check1"/> check1 <input type="checkbox" value="check2" checked="checked"/> check2 <input type="radio" value="radio1" checked="checked"/> radio1 <input type="radio" value="radio2"/> radio2 </form> jQuery 代码: var fields = $("select,:radio").serializeArray(); jQuery.each( fields, function(i, field){ $("#results").append(field.value + " "); });