Home > Article > Web Front-end > How to clear the content in input in jquery
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.
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. .
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.
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.
#4. In the test.html file, use the button tag to create a button with the button name "Clear Content".
5. In the test.html file, bind the onclick event to the button button. When the button is clicked, execute the clearinput() function.
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.
7. Open the test.html file in the browser, enter the content in the text box, click the button to see the effect.
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!