Home >Web Front-end >JS Tutorial >Use jquery to clear and reset the entire input field_jquery
In web development, we often encounter the situation of resetting all input boxes.
For example, when querying, the user will be provided with a "reset" button to clear the entered text in all input boxes.
At this time, jquery can be used to clear (reset) the data uniformly.
// 复位查询条件输入域 function restInputArea(div_id){ // 清空文本框 $("#"+div_id).find('input[type="text"]').each(function(){ $(this).val(""); }); // 复位下拉菜单 $("#"+div_id).find('select').each(function(){ $(this).find('option:first-child').attr('selected',"selected"); }); };
The above code uses the jquery selector to obtain the parent element of the entire input box, and uses find to find all input and select input boxes under the element.