Home >Web Front-end >JS Tutorial >Use jquery to clear and reset the entire input field_jquery

Use jquery to clear and reset the entire input field_jquery

WBOY
WBOYOriginal
2016-05-16 16:06:001827browse

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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn