Home > Article > Web Front-end > How to set up webpage javascript
With the booming development of the Internet, more and more websites use JavaScript to enhance user experience and website functionality. So how to set JavaScript in a web page? Some common methods and techniques will be introduced below.
1. Internal JavaScript
Internal JavaScript is a way to embed JavaScript code directly into an HTML document. Add the <script> and </script> tags between the
and of the HTML document, and place the JS code between them.For example:
<title>内部JavaScript设置</title> <script> function sayHello() { alert("Hello!"); } </script>
<button onclick="sayHello()">点击</button>
In this example, we use internal JavaScript to pop up a Hello! prompt box when clicking the button .
2. External JavaScript
External JavaScript is a way to write JavaScript code in another file and then introduce it into the web page through the
<button onclick="sayHello()">点击</button>