Home > Article > Web Front-end > jquery selector to quickly extract web form data example_jquery
I am relatively lazy. When doing web work, when I have to repeat the same thing many times, I want to find a way to save time and effort.
In the past, when submitting a form on the web and needing to verify user input, document.getElementById() was used in js when extracting user input information. This way, one or two form fields is okay, but there are many cases. (I have encountered more than a dozen situations) It’s dazzling to look at, so I am personally disgusted with this method, but fortunately, I thought about it myself and found a convenient method using jquery.
I added an additional attribute to each form field that needs to submit data, and replaced the original name attribute with my own additional defined attribute "_postField", such as and so on, and then use query to obtain all DOM objects with _postField attributes, traverse them, and encapsulate them with the value of _postField as the key. The content is a json key-value pair of value, and its js method is as follows: