Current location - Music Encyclopedia - Chinese History - How to clear the original text box when js clicks for the first time, and then click not to clear the content after entering the text?
How to clear the original text box when js clicks for the first time, and then click not to clear the content after entering the text?
1. Create a new html file and name it test.html.

2. In test.html file, create a module with div tag, and in div tag, create a line of text with p tag.

3. In the test.html file, set the id of the div tag to testid, which is mainly used to obtain the div object through the following id.

4. In the test.html file, use the button tag to create a button named "Clear the contents in div".

5. In the test.html file, bind the onclick click event to the button, and when the button is clicked, execute the clearcon () function.

6. In the js tag, create the clearcon () function. Inside the function, get the div object by id(testid) using getElementById () method, and set the innerHTML property to null, so that the contents of the div can be emptied.