JQuery - Serialize() a object that isn't a form but it's inside and part of a form
I'm trying to serialize some contents inside of a form:
<form>
<input ...>
<input ...>
<div id=div1>
<input name=input1 ...>
<input name=input2 ...>
</div>
<开发者_如何学JAVA/form>
<script>
jQuery("#div1").serialize();
</script>
In this code serialize() function doesn't serialize the input1 and input2. Even I tried
jQuery("<form>" + jQuery("div1").html() + "</form>").serialize()
And it does serialize the inputs but all the values are Empty! it's like it doesn't assign values that user entered: input1=&input2=
Is there any solutions out there? (The reason I need to do this is that this page is a ASP.NET page since ASP.NET standard is a single form based so I have to deal with this situation)
Better solution is to use the :input selector since it gets all of the form elements
jQuery('#div1 :input').serialize();
I believe this will work:
jQuery('#div1 input').serialize()
精彩评论