如果您真的只想保留一种形式,请尝试像我在此提琴中所做的那样。
为您的表单创建子部分。
<form> <div id="first"> <input name="tbox1" type="text"> <input name="tbox2" type="text"> <input name="tbox3" type="text"> <input id="button1" type="button" value="button1"> </div> <div id="second"> <input name="tbox4" type="text"> <input name="tbox5" type="text"> <input name="tbox6" type="text"> <input id="button2" type="button" value="button2"> </div></form>
然后只需选择零件的所有元素:
$(document).ready(function() { $('#button1').on('click', function() { alert($('#first input').serialize()); }); $('#button2').on('click', function() { alert($('#second input').serialize()); });});
当然,如果您还有选择框,则必须将其添加到选择器中。例如:
$('#second input, #second select').serialize()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)