Home > Web Front-end > Front-end Q&A > How to implement click switching text in html5

How to implement click switching text in html5

WBOY
Release: 2022-01-13 11:47:00
Original
6355 people have browsed it

Method: 1. Bind the click event to the button and specify the event processing function; 2. Use the "document.getElementById("Element")" statement in the function to obtain the specified text element object; 3. Use The statement "Element object.innerHTML='text'" can switch the text.

How to implement click switching text in html5

The operating environment of this tutorial: Windows 10 system, HTML5 version, Dell G3 computer.

html5How to implement click switching text

You can first bind the click event to the button element and specify the event handler function.

In the event handling function, find the text element object and use the innerHTML attribute to set the switched text.

The example is as follows:

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
</head>
<body>
  <p id="test">点击切换文本</p>
  <button onclick="editinput()">切换</button>
  <script>
    function editinput() {
      document.getElementById("test").innerHTML=&#39;切换了&#39;;
    }
  </script>
</body>
</html>
Copy after login

Output result:

How to implement click switching text in html5

##Recommended tutorial: "

html video tutorial

The above is the detailed content of How to implement click switching text in html5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template