1

To clearly defined the problem consider this example.

<form id='myform'>
    <div id='location'>
            <input type='text' name='username'>
    </div>
    <div id='background' style='display:none'>
            <input type='text' name='username'>
    </div>
    <div id='family' style='display:none'>
            <input type='text' name='username'>
    </div>
</form>

OK. Now what i am trying to do is create an edit form. First i am displaying each item of user data on a page. User data has been devided in sections like this

Location
VisualAppearance
Background
Family
EducationAndCareer
Lifestyle
AdditionalQuestions

Now for example location section contains some information about user location like

country , city , zip , state

Each item like country contains an arrow. On arrow click i send user to another page with a get parameter ?item=location. on document ready i see what is in get and then fill the related fields and display the demanded section. Load the required dropdowns and seleted items in them. Now i want to post data with ajax. If i use $('form').serialize() it will send all the sections information with null values which i dont want. Because other sections are hidded and were not loaded. I want to send data only for location in this scanrio. How can i do this.

I am working for mobile . I am using jquery and knockout for this.

4

1 回答 1

1

serialize()您可以使用简单的 CSS 选择器让 jQuery只显示表单的一部分:

$('#location :input').serialize()

小提琴

于 2013-10-14T08:31:52.427 回答