在jQuery中收集表单中的所有项目

时间:2009-06-16 15:22:51

标签: jquery forms collections

如何收集jQuery中的所有复选框和下拉列表项以进行保存?

3 个答案:

答案 0 :(得分:9)

或者,对于最新版本的jquery,您可以使用:

http://docs.jquery.com/Ajax/serialize - 以URL编码的字符串person.name=john&person.age=20

http://docs.jquery.com/Ajax/serializeArray - 到JSON

答案 1 :(得分:3)

一种方法是使用jQuery Form插件,如下所示:

$('#myFormId').formSerialize(); 

来自formSerialize API documentation

Serializes the form into a query string. This method will return a string in the format: name1=value1&name2=value2

答案 2 :(得分:1)

$( '#myFormId')formSerialize();是一个插件,可能没有必要。 核心函数serialize()更好。

http://docs.jquery.com/Ajax/serialize