<script>
tag. JavaScript locates and operates various web page elements by referencing the ID or class of the HTML element. For example, we can embed JavaScript using the following code: <html> <head> <title>JavaScript示例</title> </head> <body> <button onclick="alert('Hello World!')">点击我!</button> <script> function myFunction() { document.getElementById("demo").innerHTML = "Hello World!"; } </script> <p id="demo"></p> </body> </html>
<body>
tag, and when the user clicks the button, a popup will appear A warning box. Additionally, we define a JavaScript function called myFunction
that changes the content of the <p>
element to "Hello World!". In order to call this function in the page, we set the ID of the <p>
element to "demo" and reference the element in the JavaScript code using the document.getElementById()
method .
<p>In short, HTML and JavaScript are two indispensable tools in web development. The two interact with each other to build a feature-rich and highly interactive web page. HTML defines the structure and content of a website, while JavaScript provides dynamic interactions and functionality. Only when the two are closely integrated can we build a dynamic and engaging website that truly provides a complete user experience. The above is the detailed content of What is the relationship between javascript and html. For more information, please follow other related articles on the PHP Chinese website!