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

How to set up webpage javascript

WBOY
Release: 2023-05-06 10:10:07
Original
816 people have browsed it

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>  
Copy after login


< ;body>

<button onclick="sayHello()">点击</button>  
Copy after login
Copy after login


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

Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template