Jquery clear form data example sharing

Source: Internet
Author: User

Jquery clear form data example sharing

This article mainly introduces the example of jquery clearing form data. For more information, see

The Code is as follows:

Function clearForm (form ){

// Iterate over all of the inputs for the form

// Element that was passed in

$ (': Input', form). each (function (){

Var type = this. type;

Var tag = this. tagName. toLowerCase (); // normalize case

// It's OK to reset the value attr of text inputs,

// Password inputs, and textareas

If (type = 'text' | type = 'Password' | tag = 'textea ')

This. value = "";

// Checkboxes and radios need to have their checked state cleared

// But shoshould * not * have their 'value' changed

Else if (type = 'checkbox' | type = 'Radio ')

This. checked = false;

// Select elements need to have their 'selectedindex 'property set to-1

// (This works for both single and multiple select elements)

Else if (tag = 'select ')

This. selectedIndex =-1;

});

};

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.