Home >Web Front-end >Front-end Q&A >How to set up webpage javascript

How to set up webpage javascript

WBOY
WBOYOriginal
2023-05-06 10:10:07820browse

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>  


< ;body>

<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