jQuery serialize / serializeArray from an element that is not a form

前端 未结 4 1479
花落未央
花落未央 2020-12-03 09:36

I haven\'t found a concrete answer as to whether this is possible, but it seems like it should be...

I would like to serialize all the input elements contained in a

相关标签:
4条回答
  • 2020-12-03 10:06

    Try this, to get all.

    $('#divID *').serialize()
    
    0 讨论(0)
  • 2020-12-03 10:09

    For serializing the contents of the div with a button, this will be the more efficient way as it doesn't traverse through the entire dom.

    $(this).closest('div').find("input,select,textarea").serialize();

    make sure to attach this with the button event and make sure to include event.preventdefault with the button so that it does not submit the primary form if the div is inside it.

    0 讨论(0)
  • 2020-12-03 10:16

    this also works with

    $('div :input').serializeArray()
    

    :)

    0 讨论(0)
  • 2020-12-03 10:30

    you need to serialize all the inputs inside your container, not the actual container itself. so:

    $('div :input').serialize()
    
    0 讨论(0)
提交回复
热议问题