javascript - Serializing a subset of form - Stack Overflow

I have a form that embeds another form:<form><input type="text" name="main[name

I have a form that embeds another form:

<form>
  <input type="text" name="main[name]">
  <textarea name="main[body]"></textarea>
  <div id="embedded">
    <input type="text" name="main[embedded][name]">
    <textarea name="main[embedded][body]"></textarea>
  </div>
</form>

I need to serialize the embedded form only.

$('#embedded').serialize() results in empty string.

I have a form that embeds another form:

<form>
  <input type="text" name="main[name]">
  <textarea name="main[body]"></textarea>
  <div id="embedded">
    <input type="text" name="main[embedded][name]">
    <textarea name="main[embedded][body]"></textarea>
  </div>
</form>

I need to serialize the embedded form only.

$('#embedded').serialize() results in empty string.

Share Improve this question asked Dec 13, 2011 at 10:45 DziamidDziamid 11.6k12 gold badges72 silver badges107 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 9

You are not embedding another form, you are embedding a div.

The serialize() method can only be called on a form elements, or the form element itself.

var serialized = $('#embedded').find(':input').serialize();

The .serialize() method can act on a jQuery object that has selected individual form elements, such as <input>, <textarea>, and <select>. However, it is typically easier to select the <form> tag itself for serialization:

I haven't tested this, but you could try:

$("<form/>").html($('#embedded').clone()).serialize()

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744275699a4566319.html

相关推荐

  • javascript - Serializing a subset of form - Stack Overflow

    I have a form that embeds another form:<form><input type="text" name="main[name

    7天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信