2, the preparation of the position of JS

JS position of writing

1, JS code can be written to the onclick attribute tag ↓

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
</head>
<body>
    <!-- button是按钮标签 -->
    <= "Alert ( 'point me doing?')"onclickthe Button> Point me </ the Button > 
</ body > 
</ HTML >
View Code

When you click the "point me" button will pop up a warning box.

2, JS code can be written to a hyperlink href attribute, when you click a hyperlink, will perform JS code ↓

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
</head>
<body>
    <a href="javascript:alert ( 'ha ha ha'); " </also point me>a>
</body>
</html>
View Code

When you click a hyperlink, it will pop up a warning box.

Although written in the tag attributes, but they belong to the structure and behavior of the coupling is not recommended.

3, JS code can be written in the script tag.

4, JS code can be written to external JS file and referenced by the script tag, recommended

First create a .js file ↓

This file is then introduced into the script tag ↓

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>Document</title>
    <script type="text/javascript" src="/前端/36、JS/jswenjian/js外部引用.js"></script>
</head>
<body>
</body>
</html>
View Code

Note: Once the script tag to import external JS files, then the tag will not be able to write other JS code, wrote the browser will ignore, unless write a script tag, and then write the new script tag js code.

 

Guess you like

Origin www.cnblogs.com/StevenSunYiwen/p/11766960.html