jQuery to serialize only elements within a div

后端 未结 8 1770
猫巷女王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条回答
  •  萌比男神i
    2020-11-28 21:20

    The function I use currently:

    /**
     * Serializes form or any other element with jQuery.serialize
     * @param el
     */
    serialize: function(el) {
        var serialized = $(el).serialize();
        if (!serialized) // not a form
            serialized = $(el).
              find('input[name],select[name],textarea[name]').serialize();
        return serialized;
    }
    

提交回复
热议问题