Use jquery to clear and reset the entire input field
- 2020-05-26 07:46:09
- OfStack
In web development, we often encounter situations where all input boxes are reset.
For example, when querying, the user is given a "reset" button to clear all input text in the input box.
At this point, jquery can be used to clear (reset) 1.
// Reset the query condition input field
function restInputArea(div_id){
// Empty the textbox
$("#"+div_id).find('input[type="text"]').each(function(){
$(this).val("");
});
// Reset the drop-down menu
$("#"+div_id).find('select').each(function(){
$(this).find('option:first-child').attr('selected',"selected");
});
};
The above code USES the jquery selector to get the parent element of the entire input box and find to find all the input and select input boxes under that element.