jQuery to serialize only elements within a div

后端 未结 8 1803
猫巷女王i
猫巷女王i 2020-11-28 20:52

I would like to get the same effect as jQuery.serialize() but I would like to return only the child elments of a given div.

Sample

8条回答
  •  天涯浪人
    2020-11-28 21:35

    If those elements have a common class name, one may also use this:

    $('#your_div .your_classname').serialize()
    

    This way you can avoid selection of buttons, which will be selected using the jQuery selector :input. Though this can also be avoided by using $('#your_div :input:not(:button)').serialize();

提交回复
热议问题