[JQuery] actually clears the Form Content

Source: Internet
Author: User

[JQuery] actually clears the Form Content
JQuery: not () Selector

Definition and usage:

: Not () selector Selects all elements except the specified element.

The most common usage: used with other selectors to select all elements except the specified Element in the specified combination.

Reference code:

<Script> $ (function () {$ ("p: not (# p1)" ).css ("color", "red "); // write $ ("p "). not ("# p1" ).css ("color", "red"); // method 2}) </script>

Hello

Hello Again

Execution result:


The html dom reset () method or Element

Reference code:

<script>$(function() {$("#form1 :input").val("value");})</script>
Before clicking the reset button:


Click the reset button:


Conclusion: The html dom reset () method orThe true function of elements is not to "empty"The value in the element, but is reset to restoreThe original value in the element. It is worth noting that reset cannot reset the value of the button type element (type = button, reset, submit.


Actually clear the content in the form (JQuery)

Reference code:

<Script> $ (function () {$ ("# button "). click (function () {$ ("# form: input "). not (": button,: submit,: reset,: hidden "). val (""). removeAttr ("checked "). remove ("selected"); // core}) ;}) </script>Truly clear
Before clicking the "id = button" button:


Click "id = button:


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.