In fact, today's share is very simple, as long as you simply understand the JQ expansion method, as long as you will traverse the elements, it can be encapsulated. In the work is precisely because of such a method, greatly enhance our efficiency, reduce the number of mistakes. But we often use other people's packaged methods, which is very uncomfortable.
Hope to love the technology of the park friends will be able to do in the future, their own packaging methods, for the whole company to use people.
; (function($) {$.fn.extend ({formtoobj:function () { vardata =NewObject (); $("Input[type=text],input[type=password],input[type=radio]:checked,select", This). each (function () { varName = $ ( This). attr (' name '); Data[name]= $( This). Val (); }); returndata; } });
No more manual forms, no. There are other form elements that can be expanded on their own.
Use the method to wrap a form label on the forms.
var data=$ (' #myform '). Formtoobj ();
Just put it in Ajax and submit data!
More methods will be shared in the future. Welcome to leave your usual method!
The form data of the jquery expansion method object-thus Ajax post to the background