Home >Web Front-end >JS Tutorial >How to clear the content in input in jquery

How to clear the content in input in jquery

coldplay.xixi
coldplay.xixiOriginal
2020-11-19 15:12:567033browse

Jquery method to clear the content in the input: first create a file and use the input tag to create a text box, and use the button tag to create a button; then create a function and obtain the input object within the function; finally use [val()] to clear it The content of the input text box.

How to clear the content in input in jquery

The operating environment of this tutorial: Windows 7 system, jquery version 3.3.1. This method is suitable for all brands of computers.

How to clear the content in the input using jquery:

1. Create a new html file, named test.html, to explain how to clear the content in the input using jquery. .

How to clear the content in input in jquery

2. In the test.html file, introduce the jquery.min.js library file and successfully load the file before you can use the methods in jquery.

How to clear the content in input in jquery

3. In the test.html file, use the input tag to create a text box and set its id to myinput. It is mainly used to obtain the input object through this id below.

How to clear the content in input in jquery

#4. In the test.html file, use the button tag to create a button with the button name "Clear Content".

How to clear the content in input in jquery

5. In the test.html file, bind the onclick event to the button button. When the button is clicked, execute the clearinput() function.

How to clear the content in input in jquery

6. In the js tag, create the clearinput() function. Within the function, obtain the input object through id(myinput) and use val() to clear the input text box. content.

How to clear the content in input in jquery

7. Open the test.html file in the browser, enter the content in the text box, click the button to see the effect.

How to clear the content in input in jquery

Related free learning recommendations: JavaScript (video)

The above is the detailed content of How to clear the content in input in jquery. For more information, please follow other related articles on the PHP Chinese website!

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